Index: extras/lzma/src/main/java/com/sun/grizzly/lzma/compression/lzma/Encoder.java --- extras/lzma/src/main/java/com/sun/grizzly/lzma/compression/lzma/Encoder.java Base (BASE) +++ extras/lzma/src/main/java/com/sun/grizzly/lzma/compression/lzma/Encoder.java Locally Modified (Based On LOCAL) @@ -53,6 +53,17 @@ public static final int EMatchFinderTypeBT2 = 0; public static final int EMatchFinderTypeBT4 = 1; + + public static final int CUSTOM_COMPRESSION_LEVEL = -1; + public static final int DEFAULT_COMPRESSION_LEVEL = 3; + + static final CompressionLevel[] COMPRESSION_LEVELS = { + new CompressionLevel(131072, 5), new CompressionLevel(524288, 6), + new CompressionLevel(2097152, 7), new CompressionLevel(2097152, 12), + new CompressionLevel(2097152, 20), new CompressionLevel(4194304, 32), + new CompressionLevel(8388608, 64), new CompressionLevel(33554432, 128), + new CompressionLevel(134217728, 256)}; + static final int kIfinityPrice = 0xFFFFFFF; static byte[] g_FastPos = new byte[1 << 11]; @@ -322,6 +333,25 @@ return (BackPrev == 0); } }; + + static class CompressionLevel { + private final int dictionarySize; + private final int numFastBytes; + + public CompressionLevel(int dictionarySize, int numFastBytes) { + this.dictionarySize = dictionarySize; + this.numFastBytes = numFastBytes; + } + + public int getDictionarySize() { + return dictionarySize; + } + + public int getNumFastBytes() { + return numFastBytes; + } + } + Optimal[] _optimum = new Optimal[kNumOpts]; BinTree _matchFinder = null; com.sun.grizzly.lzma.compression.rangecoder.Encoder _rangeEncoder = new com.sun.grizzly.lzma.compression.rangecoder.Encoder(); @@ -359,6 +389,7 @@ int _numFastBytesPrev = -1; long nowPos64; boolean _finished; + int _compressionLevel = -1; java.io.InputStream _inStream; int _matchFinderType = EMatchFinderTypeBT4; boolean _writeEndMark = false; @@ -391,6 +422,10 @@ for (int i = 0; i < Base.kNumLenToPosStates; i++) { _posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits); } + + SetMatchFinder(EMatchFinderTypeBT4); + SetLcLpPb(8, 0, 0); + SetCompressionLevel(DEFAULT_COMPRESSION_LEVEL); } void SetWriteEndMarkerMode(boolean writeEndMarker) { @@ -1335,5 +1370,25 @@ public void SetEndMarkerMode(boolean endMarkerMode) { _writeEndMark = endMarkerMode; } + + public void SetCompressionLevel(int compressionLevel) { + if (compressionLevel == CUSTOM_COMPRESSION_LEVEL) { + return; } + if (compressionLevel < 1 || compressionLevel > 9) { + SetCompressionLevel(DEFAULT_COMPRESSION_LEVEL); + } + + final CompressionLevel cl = COMPRESSION_LEVELS[compressionLevel - 1]; + SetDictionarySize(cl.getDictionarySize()); + SetNumFastBytes(cl.getNumFastBytes()); + + _compressionLevel = compressionLevel; + } + + public int GetCompressionLevel() { + return _compressionLevel; + } +} + Index: modules/utils/src/main/java/com/sun/grizzly/tcp/http11/filters/LzmaOutputFilter.java --- modules/utils/src/main/java/com/sun/grizzly/tcp/http11/filters/LzmaOutputFilter.java Base (BASE) +++ modules/utils/src/main/java/com/sun/grizzly/tcp/http11/filters/LzmaOutputFilter.java Locally Modified (Based On LOCAL) @@ -154,9 +154,16 @@ private void initEncoder() throws IOException { encoder = new Encoder(); + final int compressionLevel = lzmaProperties.getCompressionLevel(); + + if (compressionLevel == Encoder.CUSTOM_COMPRESSION_LEVEL) { encoder.SetAlgorithm(lzmaProperties.getAlgorithm()); encoder.SetDictionarySize(lzmaProperties.getDictionarySize()); encoder.SetNumFastBytes(lzmaProperties.getNumFastBytes()); + } else { + encoder.SetCompressionLevel(compressionLevel); + } + encoder.SetMatchFinder(lzmaProperties.getMatchFinder()); encoder.SetLcLpPb(lzmaProperties.getLc(), lzmaProperties.getLp(), lzmaProperties.getPb()); encoder.SetEndMarkerMode(true); @@ -245,14 +252,14 @@ } public static class LzmaProperties { - + private int compressionLevel = 3; private int algorithm = 2; private int dictionarySize = 1 << 16; private int numFastBytes = 128; - private int matchFinder = 1; - private int lc = 3; + private int matchFinder = Encoder.EMatchFinderTypeBT4; + private int lc = 8; private int lp = 0; - private int pb = 2; + private int pb = 0; public LzmaProperties() { loadProperties(this); @@ -325,15 +332,24 @@ this.numFastBytes = numFastBytes; } + public int getCompressionLevel() { + return compressionLevel; + } + + public void setCompressionLevel(int compressionLevel) { + this.compressionLevel = compressionLevel; + } + public static void loadProperties(LzmaProperties properties) { + properties.compressionLevel = Integer.getInteger("lzma-filter.compression-level", 3); properties.algorithm = Integer.getInteger("lzma-filter.algorithm", 2); properties.dictionarySize = 1 << Integer.getInteger("lzma-filter.dictionary-size", 16); properties.numFastBytes = Integer.getInteger("lzma-filter.num-fast-bytes", 128); - properties.matchFinder = Integer.getInteger("lzma-filter.match-finder", 1); + properties.matchFinder = Integer.getInteger("lzma-filter.match-finder", Encoder.EMatchFinderTypeBT4); - properties.lc = Integer.getInteger("lzma-filter.lc", 3); + properties.lc = Integer.getInteger("lzma-filter.lc", 8); properties.lp = Integer.getInteger("lzma-filter.lp", 0); - properties.pb = Integer.getInteger("lzma-filter.pb", 2); + properties.pb = Integer.getInteger("lzma-filter.pb", 0); } } }