Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding LZMA-java codec

  • Loading branch information...
commit 6cc0d385bbf75a0c3e9c7c463c0057c18d6fc8b6 1 parent fe7e711
Tatu authored
View
1  build.xml
@@ -5,6 +5,7 @@
<property name="dir.lib" value="${basedir}/lib"/>
<property name="dir.bin" value="${basedir}/bin"/>
<property name="dir.src.java" value="${basedir}/src/main/java"/>
+ <property name="dir.build" value="${basedir}/build"/>
<property name="dir.build.classes" value="${basedir}/build/classes"/>
<!-- Distribution -->
<property name="dir.dist" location="${basedir}/dist" />
View
8 cfg/drivers-all.xml
@@ -10,6 +10,12 @@
xmlns="http://www.sun.com/japex/testSuite"
xmlns:xi="http://www.w3.org/2001/XInclude"
>
+ <driver name="LZMA-java/stream">
+ <description><div xmlns=""><p>LZMA-java, streaming</p></div></description>
+ <param name="japex.classPath" value="build/classes"/>
+ <param name="japex.classPath" value="lib/lzma-java/*.jar"/>
+ <param name="japex.driverClass" value="com.ning.jcbm.lzma.LzmaJavaDriver" />
+ </driver>
<driver name="Snappy(JNI)/block" normal="false">
<description><div xmlns=""><p>Snappy-java, block mode</p></div></description>
<param name="japex.classPath" value="build/classes"/>
@@ -77,7 +83,7 @@
<param name="japex.classPath" value="lib/jakarta/*.jar"/>
<param name="japex.driverClass" value="com.ning.jcbm.bzip2.BZip2Driver" />
</driver>
- <driver name="LZMA/block">
+ <driver name="LZMA-orig/block">
<description><div xmlns=""><p>7Zip's LZMA, block mode</p></div></description>
<param name="japex.classPath" value="build/classes"/>
<param name="japex.classPath" value="lib/lzma/*.jar"/>
View
BIN  lib/lzma-java/lzma-java-1.3-SNAPSHOT.jar
Binary file not shown
View
1  src/main/java/com/ning/jcbm/bzip2/BZip2Driver.java
@@ -44,5 +44,4 @@ protected int uncompressFromStream(InputStream compIn, byte[] inputBuffer) throw
}
return total;
}
-
}
View
4 src/main/java/com/ning/jcbm/lzma/LzmaDriver.java
@@ -4,6 +4,10 @@
import com.ning.jcbm.DriverBase;
+/**
+ * Driver that uses original conversion done by LZMA author.
+ * Codec is not supported any more (AFAIK).
+ */
public class LzmaDriver extends DriverBase
{
static final int DEFAULT_ALGORITHM = 2;
View
71 src/main/java/com/ning/jcbm/lzma/LzmaJavaDriver.java
@@ -0,0 +1,71 @@
+package com.ning.jcbm.lzma;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import lzma.streams.LzmaInputStream;
+import lzma.streams.LzmaOutputStream;
+import lzma.sdk.lzma.Decoder;
+
+import com.ning.jcbm.DriverBase;
+
+/**
+ * Driver for more up-to-date LZMA codec from
+ * [https://github.com/jponge/lzma-java].
+ * Project is active, code maintained.
+ */
+public class LzmaJavaDriver extends DriverBase
+{
+ public LzmaJavaDriver() {
+ super("LZMA-java");
+ }
+
+ // No native Block API; but need some impl for test framework
+
+ protected byte[] compressBlock(byte[] uncompressed) throws IOException {
+ return compressBlockUsingStream(uncompressed);
+ }
+
+ protected byte[] uncompressBlock(byte[] compressed) throws IOException {
+ return uncompressBlockUsingStream(
+ new LzmaInputStream(new ByteArrayInputStream(compressed), getDecoder()));
+ }
+
+ protected void compressToStream(byte[] uncompressed, OutputStream rawOut) throws IOException
+ {
+ LzmaOutputStream compressedOut = new LzmaOutputStream.Builder(
+ // do we really need compressed stream here? probably not, it's ByteArrayOutputStream
+ //new BufferedOutputStream(new FileOutputStream(compressed)))
+ rawOut)
+ // how about other settings? are defaults ok?
+ /*
+ .useMaximalDictionarySize()
+ .useEndMarkerMode(true)
+ .useBT4MatchFinder()
+ */
+ .build();
+ compressedOut.write(uncompressed);
+ compressedOut.close();
+ }
+
+ protected int uncompressFromStream(InputStream compIn, byte[] inputBuffer) throws IOException
+ {
+ // as above, we get a ByteArrayInputStream so no buffering needed:
+ // (but would reuse of Decoder help?)
+ LzmaInputStream compressedIn = new LzmaInputStream(compIn, getDecoder());
+
+ int total = 0;
+ int count;
+
+ while ((count = compressedIn.read(inputBuffer)) >= 0) {
+ total += count;
+ }
+ return total;
+ }
+
+ protected Decoder getDecoder() {
+ return new Decoder();
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.