use of java.util.zip.Inflater in project Notes by MiCode.
the class GTaskClient method getResponseContent.
private String getResponseContent(HttpEntity entity) throws IOException {
String contentEncoding = null;
if (entity.getContentEncoding() != null) {
contentEncoding = entity.getContentEncoding().getValue();
Log.d(TAG, "encoding: " + contentEncoding);
}
InputStream input = entity.getContent();
if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
input = new GZIPInputStream(entity.getContent());
} else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) {
Inflater inflater = new Inflater(true);
input = new InflaterInputStream(entity.getContent(), inflater);
}
try {
InputStreamReader isr = new InputStreamReader(input);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while (true) {
String buff = br.readLine();
if (buff == null) {
return sb.toString();
}
sb = sb.append(buff);
}
} finally {
input.close();
}
}
use of java.util.zip.Inflater in project Mycat-Server by MyCATApache.
the class CompressUtil method decompress.
/**
* 适用于mysql与客户端交互时zlib解压
*
* @param data 数据
* @param off 偏移量
* @param len 长度
* @return
*/
public static byte[] decompress(byte[] data, int off, int len) {
byte[] output = null;
Inflater decompresser = new Inflater();
decompresser.reset();
decompresser.setInput(data, off, len);
ByteArrayOutputStream out = new ByteArrayOutputStream(data.length);
try {
byte[] result = new byte[1024];
while (!decompresser.finished()) {
int i = decompresser.inflate(result);
out.write(result, 0, i);
}
output = out.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
out.close();
} catch (Exception e) {
}
decompresser.end();
}
return output;
}
use of java.util.zip.Inflater in project phonegap-facebook-plugin by Wizcorp.
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));
}
use of java.util.zip.Inflater in project mapdb by jankotek.
the class SerializerCompressionDeflateWrapper method deserialize.
@Override
public E deserialize(DataInput2 in, int available) throws IOException {
final int unpackedSize = in.unpackInt() - 1;
if (unpackedSize == -1) {
//was not compressed
return serializer.deserialize(in, available > 0 ? available - 1 : available);
}
Inflater inflater = new Inflater();
if (dictionary != null) {
inflater.setDictionary(dictionary);
}
InflaterInputStream in4 = new InflaterInputStream(new DataInput2.DataInputToStream(in), inflater);
byte[] unpacked = new byte[unpackedSize];
in4.read(unpacked, 0, unpackedSize);
DataInput2.ByteArray in2 = new DataInput2.ByteArray(unpacked);
E ret = serializer.deserialize(in2, unpackedSize);
if (CC.ASSERT && !(in2.pos == unpackedSize))
throw new DBException.DataCorruption("data were not fully read");
return ret;
}
use of java.util.zip.Inflater in project jersey by jersey.
the class DeflateEncoder method decode.
@Override
public InputStream decode(String contentEncoding, InputStream encodedStream) throws IOException {
// correct impl. should wrap deflate in zlib, but some don't do it - have to identify, which one we got
InputStream markSupportingStream = encodedStream.markSupported() ? encodedStream : new BufferedInputStream(encodedStream);
markSupportingStream.mark(1);
// read the first byte
int firstByte = markSupportingStream.read();
markSupportingStream.reset();
// that should never be the case if no zlib wrapper
if ((firstByte & 15) == 8) {
// ok, zlib wrapped stream
return new InflaterInputStream(markSupportingStream);
} else {
// no zlib wrapper
return new InflaterInputStream(markSupportingStream, new Inflater(true));
}
}
Aggregations