]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.fastlz/src/org/simantics/fastlz/FastLZJava.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / FastLZJava.java
diff --git a/bundles/org.simantics.fastlz/src/org/simantics/fastlz/FastLZJava.java b/bundles/org.simantics.fastlz/src/org/simantics/fastlz/FastLZJava.java
new file mode 100644 (file)
index 0000000..3e0f452
--- /dev/null
@@ -0,0 +1,98 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 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.fastlz;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+\r
+import org.simantics.fastlz.java.FastLZImpl;\r
+import org.simantics.fastlz.java.FastLZJavaInputStream;\r
+import org.simantics.fastlz.java.FastLZJavaOutputStream;\r
+\r
+/**\r
+ * A Java port of the native {@link FastLZ} library.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * \r
+ * @see FastLZ\r
+ * @see FastLZImpl\r
+ * @see FastLZJavaInputStream\r
+ * @see FastLZJavaOutputStream\r
+ */\r
+public class FastLZJava {\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 must be at least 5% larger than the input buffer and\r
+     * can not be smaller than 66 bytes.\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
+    public static int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) {\r
+        return FastLZImpl.fastlz_compress(input, inputOffset, length, output, outputOffset);\r
+    }\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
+    public static int decompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset, int maxout) {\r
+        return FastLZImpl.fastlz_decompress(input, inputOffset, length, output, outputOffset, maxout);\r
+    }\r
+\r
+    /**\r
+     * @param file the FastLZ-compressed file to read\r
+     * @return input stream that decompresses its output using the FastLZ\r
+     *         algorithm\r
+     * @throws FileNotFoundException see\r
+     *         {@link FileOutputStream#FileOutputStream(File)} for when this is\r
+     *         thrown\r
+     */\r
+    public static InputStream read(File file) throws FileNotFoundException {\r
+        return new FastLZJavaInputStream(new FileInputStream(file));\r
+    }\r
+\r
+    /**\r
+     * @param file the FastLZ-compressed file to write\r
+     * @return output stream that compresses its input using the FastLZ\r
+     *         algorithm\r
+     * @throws FileNotFoundException see\r
+     *         {@link FileOutputStream#FileOutputStream(File)} for when this is\r
+     *         thrown\r
+     */\r
+    public static OutputStream write(File file) throws FileNotFoundException {\r
+        return new FastLZJavaOutputStream(new FileOutputStream(file));\r
+    }\r
+\r
+}\r