Skip to content

Commit

Permalink
Adding LZMA-java codec
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatu committed Jul 21, 2011
1 parent fe7e711 commit 6cc0d38
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -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" />
Expand Down
8 changes: 7 additions & 1 deletion cfg/drivers-all.xml
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down
Binary file added lib/lzma-java/lzma-java-1.3-SNAPSHOT.jar
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/com/ning/jcbm/bzip2/BZip2Driver.java
Expand Up @@ -44,5 +44,4 @@ protected int uncompressFromStream(InputStream compIn, byte[] inputBuffer) throw
}
return total;
}

}
4 changes: 4 additions & 0 deletions src/main/java/com/ning/jcbm/lzma/LzmaDriver.java
Expand Up @@ -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;
Expand Down
71 changes: 71 additions & 0 deletions 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();
}
}

0 comments on commit 6cc0d38

Please sign in to comment.