use of java.util.zip.InflaterInputStream in project gerrit by GerritCodeReview.
the class PatchList method readObject.
private void readObject(ObjectInputStream input) throws IOException {
final ByteArrayInputStream buf = new ByteArrayInputStream(readBytes(input));
try (InflaterInputStream in = new InflaterInputStream(buf)) {
oldId = read(in);
newId = readWithoutMarker(in);
isMerge = readVarInt32(in) != 0;
comparisonType = ComparisonType.readFrom(in);
insertions = readVarInt32(in);
deletions = readVarInt32(in);
final int cnt = readVarInt32(in);
final PatchListEntry[] all = new PatchListEntry[cnt];
for (int i = 0; i < all.length; i++) {
all[i] = PatchListEntry.readFrom(in);
}
patches = all;
}
}
use of java.util.zip.InflaterInputStream in project okio by square.
the class DeflaterSinkTest method inflate.
/**
* Uses streaming decompression to inflate {@code deflated}. The input must
* either be finished or have a trailing sync flush.
*/
private Buffer inflate(Buffer deflated) throws IOException {
InputStream deflatedIn = deflated.inputStream();
Inflater inflater = new Inflater();
InputStream inflatedIn = new InflaterInputStream(deflatedIn, inflater);
Buffer result = new Buffer();
byte[] buffer = new byte[8192];
while (!inflater.needsInput() || deflated.size() > 0 || deflatedIn.available() > 0) {
int count = inflatedIn.read(buffer, 0, buffer.length);
if (count != -1) {
result.write(buffer, 0, count);
}
}
return result;
}
use of java.util.zip.InflaterInputStream in project ddf by codice.
the class SamlSecurity method inflateBase64.
@Override
public String inflateBase64(String base64EncodedValue) throws IOException {
if (base64EncodedValue == null) {
return "";
}
byte[] deflatedValue = Base64.getMimeDecoder().decode(base64EncodedValue.getBytes(StandardCharsets.UTF_8));
InputStream is = new InflaterInputStream(new ByteArrayInputStream(deflatedValue), new Inflater(GZIP_COMPATIBLE));
return IOUtils.toString(is, StandardCharsets.UTF_8.name());
}
use of java.util.zip.InflaterInputStream in project ddf by codice.
the class SamlSecurityTest method testInflateDeflateWithTokenDuplication.
@Test
public void testInflateDeflateWithTokenDuplication() throws Exception {
String token = "valid_grant valid_grant valid_grant valid_grant valid_grant valid_grant";
DeflateEncoderDecoder deflateEncoderDecoder = new DeflateEncoderDecoder();
byte[] deflatedToken = deflateEncoderDecoder.deflateToken(token.getBytes());
String cxfInflatedToken = IOUtils.toString(deflateEncoderDecoder.inflateToken(deflatedToken));
String streamInflatedToken = IOUtils.toString(new InflaterInputStream(new ByteArrayInputStream(deflatedToken), new Inflater(true)));
assertNotSame(cxfInflatedToken, token);
assertEquals(streamInflatedToken, token);
}
use of java.util.zip.InflaterInputStream in project nutch by apache.
the class DeflateUtils method inflate.
/**
* Returns an inflated copy of the input array.
* @param in Deflated byte array
* @return An inflated copy of the input array, otherwise null
* @throws IOException
* if the input cannot be properly decompressed
*/
public static final byte[] inflate(byte[] in) throws IOException {
// decompress using InflaterInputStream
ByteArrayOutputStream outStream = new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
InflaterInputStream inStream = new InflaterInputStream(new ByteArrayInputStream(in));
byte[] buf = new byte[BUF_SIZE];
while (true) {
int size = inStream.read(buf);
if (size <= 0)
break;
outStream.write(buf, 0, size);
}
outStream.close();
return outStream.toByteArray();
}
Aggregations