use of java.util.zip.Inflater in project j2objc by google.
the class InflaterTest method testInflaterCounts.
public void testInflaterCounts() throws Exception {
Inflater inflater = new Inflater();
byte[] decompressed = new byte[32];
byte[] compressed = deflate(new byte[] { 1, 2, 3 }, null);
assertEquals(11, compressed.length);
// Feed in bytes [0, 5) to the first iteration.
inflater.setInput(compressed, 0, 5);
inflater.inflate(decompressed, 0, decompressed.length);
assertEquals(5, inflater.getBytesRead());
assertEquals(5, inflater.getTotalIn());
assertEquals(2, inflater.getBytesWritten());
assertEquals(2, inflater.getTotalOut());
// Feed in bytes [5, 11) to the second iteration.
assertEquals(true, inflater.needsInput());
inflater.setInput(compressed, 5, 6);
assertEquals(1, inflater.inflate(decompressed, 0, decompressed.length));
assertEquals(11, inflater.getBytesRead());
assertEquals(11, inflater.getTotalIn());
assertEquals(3, inflater.getBytesWritten());
assertEquals(3, inflater.getTotalOut());
inflater.reset();
assertEquals(0, inflater.getBytesRead());
assertEquals(0, inflater.getTotalIn());
assertEquals(0, inflater.getBytesWritten());
assertEquals(0, inflater.getTotalOut());
}
use of java.util.zip.Inflater in project j2objc by google.
the class OldAndroidDeflateTest method simpleTest.
/*
* Simple inflate/deflate test, taken from the reference docs for the
* Inflater/Deflater classes.
*/
private void simpleTest() throws UnsupportedEncodingException, DataFormatException {
// Encode a String into bytes
String inputString = "blahblahblah??";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0, compressedDataLength);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");
assertEquals(inputString, outputString);
assertEquals(compresser.getAdler(), decompresser.getAdler());
decompresser.end();
}
use of java.util.zip.Inflater in project j2objc by google.
the class OldAndroidDeflateTest method bigTest.
/*
* "step" determines how compressible the data is.
*
* Note we must set "nowrap" to false, or the Adler-32 doesn't get
* computed.
*/
private void bigTest(int step, int expectedAdler) throws UnsupportedEncodingException, DataFormatException {
byte[] input = new byte[128 * 1024];
byte[] comp = new byte[128 * 1024 + 512];
byte[] output = new byte[128 * 1024 + 512];
Inflater inflater = new Inflater(false);
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, false);
createSample(input, step);
compress(deflater, input, comp);
expand(inflater, comp, (int) deflater.getBytesWritten(), output);
assertEquals(inflater.getBytesWritten(), input.length);
assertEquals(deflater.getAdler(), inflater.getAdler());
assertEquals(deflater.getAdler(), expectedAdler);
}
use of java.util.zip.Inflater in project dex2jar by pxb1988.
the class ZipFile method getInputStream.
/**
* Returns an input stream on the data of the specified {@code android.ZipEntry}.
*
* @param entry
* the android.ZipEntry.
* @return an input stream of the data contained in the {@code android.ZipEntry}.
* @throws java.io.IOException
* if an {@code IOException} occurs.
* @throws IllegalStateException
* if this zip file has been closed.
*/
public InputStream getInputStream(ZipEntry entry) throws IOException {
long entryDataStart = getEntryDataStart(entry);
ByteBuffer is = (ByteBuffer) raf.duplicate().position((int) entryDataStart);
if (entry.compressionMethod == ZipEntry.STORED) {
final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN).limit((int) entry.size);
return new ByteBufferBackedInputStream(buf);
} else {
final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN).limit((int) entry.compressedSize);
int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
return new ZipInflaterInputStream(new ByteBufferBackedInputStream(buf), new Inflater(true), bufSize, entry);
}
}
use of java.util.zip.Inflater in project cordova-android-chromeview by thedracle.
the class SpdyReader method newNameValueBlockStream.
private DataInputStream newNameValueBlockStream() {
// Limit the inflater input stream to only those bytes in the Name/Value block.
final InputStream throttleStream = new InputStream() {
@Override
public int read() throws IOException {
return Util.readSingleByte(this);
}
@Override
public int read(byte[] buffer, int offset, int byteCount) throws IOException {
byteCount = Math.min(byteCount, compressedLimit);
int consumed = in.read(buffer, offset, byteCount);
compressedLimit -= consumed;
return consumed;
}
@Override
public void close() throws IOException {
in.close();
}
};
// Subclass inflater to install a dictionary when it's needed.
Inflater inflater = new Inflater() {
@Override
public int inflate(byte[] buffer, int offset, int count) throws DataFormatException {
int result = super.inflate(buffer, offset, count);
if (result == 0 && needsDictionary()) {
setDictionary(DICTIONARY);
result = super.inflate(buffer, offset, count);
}
return result;
}
};
return new DataInputStream(new InflaterInputStream(throttleStream, inflater));
}
Aggregations