Demonstration of BFINAL

This commit is contained in:
Joakim Erdfelt 2014-02-14 09:02:48 -07:00
parent c1f547e2b3
commit 6b1f17b503
1 changed files with 11 additions and 15 deletions

View File

@ -33,33 +33,29 @@ public class DeflateTest
public String deflate(String inputHex, Deflater deflater, int flushMode) public String deflate(String inputHex, Deflater deflater, int flushMode)
{ {
byte uncompressed[] = Hex.asByteArray(inputHex); byte uncompressed[] = Hex.asByteArray(inputHex);
deflater.reset();
deflater.setInput(uncompressed,0,uncompressed.length); deflater.setInput(uncompressed,0,uncompressed.length);
deflater.finish(); if (flushMode != Deflater.SYNC_FLUSH)
deflater.finish();
ByteBuffer out = ByteBuffer.allocate(bufSize); ByteBuffer out = ByteBuffer.allocate(bufSize);
byte buf[] = new byte[64]; byte buf[] = new byte[64];
while (!deflater.finished())
{ int len = deflater.deflate(buf,0,buf.length,flushMode);
int len = deflater.deflate(buf,0,buf.length,flushMode); out.put(buf,0,len);
out.put(buf,0,len);
}
out.flip(); out.flip();
return Hex.asHex(out); return Hex.asHex(out);
} }
@Test @Test
@Ignore("just noisy") @Ignore("noisy")
public void deflateAllTypes() public void deflateAllTypes()
{ {
int levels[] = new int[] int levels[] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; boolean nowraps[] = new boolean[] { true, false };
boolean nowraps[] = new boolean[] int strategies[] = new int[] { Deflater.DEFAULT_STRATEGY, Deflater.FILTERED, Deflater.HUFFMAN_ONLY };
{ true, false }; int flushmodes[] = new int[] { Deflater.NO_FLUSH, Deflater.SYNC_FLUSH, Deflater.FULL_FLUSH };
int strategies[] = new int[]
{ Deflater.DEFAULT_STRATEGY, Deflater.FILTERED, Deflater.HUFFMAN_ONLY };
int flushmodes[] = new int[]
{ Deflater.NO_FLUSH, Deflater.SYNC_FLUSH, Deflater.FULL_FLUSH };
String inputHex = Hex.asHex(StringUtil.getUtf8Bytes("time:")); String inputHex = Hex.asHex(StringUtil.getUtf8Bytes("time:"));
for (int level : levels) for (int level : levels)