forked from ning/jvm-compressor-benchmark
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tatu
committed
Jul 21, 2011
1 parent
fe7e711
commit 6cc0d38
Showing
6 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,4 @@ protected int uncompressFromStream(InputStream compIn, byte[] inputBuffer) throw | |
} | ||
return total; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |