]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaInputStream.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / java / FastLZJavaInputStream.java
diff --git a/bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaInputStream.java b/bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaInputStream.java
new file mode 100644 (file)
index 0000000..d6ac308
--- /dev/null
@@ -0,0 +1,55 @@
+/*******************************************************************************\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.java;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.nio.ByteBuffer;\r
+import java.nio.channels.ReadableByteChannel;\r
+\r
+import org.simantics.compressions.impl.DecompressingInputStream;\r
+import org.simantics.fastlz.FastLZJava;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class FastLZJavaInputStream extends DecompressingInputStream {\r
+\r
+    public FastLZJavaInputStream(File file) throws FileNotFoundException {\r
+        super(file);\r
+    }\r
+\r
+    public FastLZJavaInputStream(FileInputStream stream) {\r
+        super(stream);\r
+    }\r
+\r
+    public FastLZJavaInputStream(InputStream stream) {\r
+        super(stream);\r
+    }\r
+\r
+    public FastLZJavaInputStream(InputStream stream, ReadableByteChannel channel) {\r
+        super(stream, channel);\r
+    }\r
+\r
+    @Override\r
+    public void decompress(ByteBuffer compressed, int compressedOffset, int compressedSize, ByteBuffer uncompressed,\r
+            int uncompressedOffset, int uncompressedSize) throws IOException {\r
+        int decompressed = FastLZJava.decompress(compressed.array(), 0,\r
+                compressedSize, uncompressed.array(), 0, uncompressedSize);\r
+        if (decompressed != uncompressedSize)\r
+            throw new IOException("decompressed " + decompressed + " bytes when " + uncompressedSize + " bytes were expected.");\r
+    }\r
+\r
+}\r