use of java.util.zip.Inflater in project k-9 by k9mail.
the class ImapConnection method enableCompression.
private void enableCompression() throws IOException, MessagingException {
try {
executeSimpleCommand(Commands.COMPRESS_DEFLATE);
} catch (NegativeImapResponseException e) {
Log.d(LOG_TAG, "Unable to negotiate compression: " + e.getMessage());
return;
}
try {
InflaterInputStream input = new InflaterInputStream(socket.getInputStream(), new Inflater(true));
ZOutputStream output = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_SPEED, true);
output.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
setUpStreamsAndParser(input, output);
if (K9MailLib.isDebug()) {
Log.i(LOG_TAG, "Compression enabled for " + getLogId());
}
} catch (IOException e) {
close();
Log.e(LOG_TAG, "Error enabling compression", e);
}
}
use of java.util.zip.Inflater in project AndroidAsync by koush.
the class HybiParser method finalize.
@Override
protected void finalize() throws Throwable {
Inflater inflater = mInflater;
if (inflater != null) {
try {
inflater.end();
} catch (Exception e) {
Log.e(TAG, "inflater.end failed", e);
}
}
super.finalize();
}
use of java.util.zip.Inflater in project rest.li by linkedin.
the class DeflateCompressor method inflate.
@Override
public byte[] inflate(InputStream data) throws CompressionException {
byte[] input;
try {
input = IOUtils.toByteArray(data);
} catch (IOException e) {
throw new CompressionException(CompressionConstants.DECODING_ERROR + CompressionConstants.BAD_STREAM, e);
}
Inflater zlib = new Inflater();
zlib.setInput(input);
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] temp = new byte[CompressionConstants.BUFFER_SIZE];
int bytesRead;
while (!zlib.finished()) {
try {
bytesRead = zlib.inflate(temp);
} catch (DataFormatException e) {
throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e);
}
if (bytesRead == 0) {
if (!zlib.needsInput()) {
throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName());
} else {
break;
}
}
if (bytesRead > 0) {
output.write(temp, 0, bytesRead);
}
}
zlib.end();
return output.toByteArray();
}
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 robovm by robovm.
the class OldAndroidZipStressTest method testZipDeflateInflateStress.
/**
* Native memory allocated by Deflater in system_server. The fix reduced
* some internal ZLIB buffers in size, so this test is trying to execute a
* lot of deflating to ensure that things are still working properly.
* http://b/1185084
*/
public void testZipDeflateInflateStress() throws Exception {
final int DATA_SIZE = 16384;
// Seed makes test reproducible
Random random = new Random(42);
// Outer loop selects "mode" of test.
for (int j = 1; j <= 2; j++) {
byte[] input = new byte[DATA_SIZE];
if (j == 1) {
// Totally random content
random.nextBytes(input);
} else {
// Random contents with longer repetitions
int pos = 0;
while (pos < input.length) {
byte what = (byte) random.nextInt(256);
int howMany = random.nextInt(32);
if (pos + howMany >= input.length) {
howMany = input.length - pos;
}
Arrays.fill(input, pos, pos + howMany, what);
pos += howMany;
}
}
// Inner loop tries all 9 compression levels.
for (int i = 1; i <= 9; i++) {
System.out.println("ZipDeflateInflateStress test (" + j + "," + i + ")...");
// Just to make sure...
byte[] zipped = new byte[2 * DATA_SIZE];
Deflater deflater = new Deflater(i);
deflater.setInput(input);
deflater.finish();
deflater.deflate(zipped);
deflater.end();
byte[] output = new byte[DATA_SIZE];
Inflater inflater = new Inflater();
inflater.setInput(zipped);
inflater.finished();
inflater.inflate(output);
inflater.end();
assertEquals(input, output);
}
}
}
Aggregations