--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.compressions;\r
+\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.nio.ByteBuffer;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public interface CompressionCodec {\r
+\r
+ /**\r
+ * @param inputSize size of uncompressed input data in bytes\r
+ * @return maximum amount of bytes needed for the compressed data\r
+ */\r
+ int compressBound(int inputSize);\r
+\r
+ int compress(byte[] uncompressedData, int i, int length,\r
+ byte[] compressedData, int j);\r
+ \r
+ /**\r
+ * Compress a block of data in the input buffer and returns the size of\r
+ * compressed block. The size of input buffer is specified by length. The\r
+ * minimum input buffer size is 16.\r
+ * \r
+ * <p>\r
+ * The output buffer size must be at least what is reported y\r
+ * {@link #compressBound(int)} for the input data size.\r
+ * \r
+ * <p>\r
+ * If the input is not compressible, the return value might be larger than\r
+ * length (input buffer size).\r
+ * \r
+ * <p>\r
+ * The input buffer and the output buffer can not overlap.\r
+ * \r
+ * <p>\r
+ * It is recommended to have both input buffers as direct or heap buffers,\r
+ * not mixed. Mixing different types of buffers will hurt performance a lot.\r
+ * If both buffers are direct byte buffers and native decompression is\r
+ * available, it will be employed.\r
+ */\r
+ int compressBuffer(ByteBuffer input, int inputOffset, int length,\r
+ ByteBuffer output, int outputOffset);\r
+\r
+ byte[] decompress(byte[] compressedData, int i, int uncompressedLength);\r
+ \r
+ /**\r
+ * Decompress a block of compressed data and returns the size of the\r
+ * decompressed block. If error occurs, e.g. the compressed data is\r
+ * corrupted or the output buffer is not large enough, then 0 (zero) will be\r
+ * returned instead.\r
+ * \r
+ * <p>\r
+ * The input buffer and the output buffer can not overlap.\r
+ * \r
+ * <p>\r
+ * Decompression is memory safe and guaranteed not to write the output\r
+ * buffer more than what is specified in maxout.\r
+ * \r
+ * <p>\r
+ * It is recommended to have both input buffers as direct or heap buffers,\r
+ * not mixed. Mixing different types of buffers will hurt performance a lot.\r
+ * If both buffers are direct byte buffers and native decompression is\r
+ * available, it will be employed.\r
+ */\r
+ int decompressBuffer(ByteBuffer input, int inputOffset, int length,\r
+ ByteBuffer output, int outputOffset, int maxout);\r
+\r
+ /**\r
+ * @param file\r
+ * the compressed file to read\r
+ * @return input stream that decompresses its output using the codec's\r
+ * algorithm\r
+ * @throws FileNotFoundException\r
+ * see {@link FileOutputStream#FileOutputStream(File)} for when\r
+ * this is thrown\r
+ */\r
+ InputStream read(File file) throws FileNotFoundException;\r
+\r
+ /**\r
+ * @param file\r
+ * the compressed file to write\r
+ * @return output stream that compresses its input using the codec's\r
+ * algorithm\r
+ * @throws FileNotFoundException\r
+ * see {@link FileOutputStream#FileOutputStream(File)} for when\r
+ * this is thrown\r
+ */\r
+ OutputStream write(File file) throws FileNotFoundException;\r
+\r
+ String getId();\r
+\r
+}
\ No newline at end of file