diff --git a/build.xml b/build.xml
index 59a5f34..ad31e4e 100644
--- a/build.xml
+++ b/build.xml
@@ -21,6 +21,7 @@
+
diff --git a/lib/lzma.jar b/lib/lzma.jar
new file mode 100644
index 0000000..29a44e3
Binary files /dev/null and b/lib/lzma.jar differ
diff --git a/src/com/google/typography/font/compression/CompressLzma.java b/src/com/google/typography/font/compression/CompressLzma.java
index 5b749c1..f0f7f80 100644
--- a/src/com/google/typography/font/compression/CompressLzma.java
+++ b/src/com/google/typography/font/compression/CompressLzma.java
@@ -2,21 +2,41 @@
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)
*/
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) {
try {
- String[] args = {"/usr/bin/lzma"};
- CommandResult result = new Command(args).execute(input);
- return result.getStdout();
- } catch (CommandException e) {
+ ByteArrayInputStream in = new ByteArrayInputStream(input);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ 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);
}
}
-
}