Use SevenZip Java LZMA compression library
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
<zipfileset src="lib/guava-11.0.1.jar" />
|
<zipfileset src="lib/guava-11.0.1.jar" />
|
||||||
<zipfileset src="lib/sfntly.jar" />
|
<zipfileset src="lib/sfntly.jar" />
|
||||||
<zipfileset src="lib/woffconverter.jar" />
|
<zipfileset src="lib/woffconverter.jar" />
|
||||||
|
<zipfileset src="lib/lzma.jar" />
|
||||||
<manifest>
|
<manifest>
|
||||||
<attribute name="Main-Class" value="com.google.typography.font.compression.CompressionRunner" />
|
<attribute name="Main-Class" value="com.google.typography.font.compression.CompressionRunner" />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
Binary file not shown.
@@ -2,21 +2,41 @@
|
|||||||
|
|
||||||
package com.google.typography.font.compression;
|
package com.google.typography.font.compression;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import SevenZip.Compression.LZMA.Encoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author raph@google.com (Raph Levien)
|
* @author raph@google.com (Raph Levien)
|
||||||
*/
|
*/
|
||||||
public class CompressLzma {
|
public class CompressLzma {
|
||||||
// This is currently implemented by shelling out to a command line helper,
|
|
||||||
// which is fine for research purposes, but obviously problematic for
|
|
||||||
// production.
|
|
||||||
public static byte[] compress(byte[] input) {
|
public static byte[] compress(byte[] input) {
|
||||||
try {
|
try {
|
||||||
String[] args = {"/usr/bin/lzma"};
|
ByteArrayInputStream in = new ByteArrayInputStream(input);
|
||||||
CommandResult result = new Command(args).execute(input);
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
return result.getStdout();
|
|
||||||
} catch (CommandException e) {
|
Encoder encoder = new Encoder();
|
||||||
|
encoder.SetAlgorithm(2);
|
||||||
|
encoder.SetDictionarySize(1 << 23);
|
||||||
|
encoder.SetNumFastBytes(128);
|
||||||
|
encoder.SetMatchFinder(1);
|
||||||
|
encoder.SetLcLpPb(3, 0, 2);
|
||||||
|
encoder.SetEndMarkerMode(true);
|
||||||
|
encoder.WriteCoderProperties(out);
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
out.write((int) ((long) -1 >>> (8 * i)) & 0xFF);
|
||||||
|
}
|
||||||
|
encoder.Code(in, out, -1, -1, null);
|
||||||
|
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
return out.toByteArray();
|
||||||
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user