private BufferedSource getNativeSource(BufferedSource input, boolean isGzipped) { if (isGzipped) { GzipSource source = new GzipSource(input); return Okio.buffer(source); } else { return input; } }
private Buffer gunzip(Buffer gzipped) throws IOException { Buffer result = new Buffer(); GzipSource source = new GzipSource(gzipped); while (source.read(result, Integer.MAX_VALUE) != -1) { } return result; } }
GzipSource gzippedResponseBody = null; try { gzippedResponseBody = new GzipSource(buffer.clone()); buffer = new Buffer(); buffer.writeAll(gzippedResponseBody); } finally { if (gzippedResponseBody != null) { gzippedResponseBody.close();
private byte[] parseGzipResponseBody(ResponseBody body) throws IOException{ Buffer buffer = new Buffer(); GzipSource gzipSource = new GzipSource(body.source()); while (gzipSource.read(buffer, Integer.MAX_VALUE) != -1) { } gzipSource.close(); return buffer.readByteArray(); }
byte flags = source.buffer().getByte(3); boolean fhcrc = ((flags >> FHCRC) & 1) == 1; if (fhcrc) updateCrc(source.buffer(), 0, 10); checkEqual("ID1ID2", (short) 0x1f8b, id1id2); source.skip(8); if (fhcrc) updateCrc(source.buffer(), 0, 2); int xlen = source.buffer().readShortLe(); source.require(xlen); if (fhcrc) updateCrc(source.buffer(), 0, xlen); source.skip(xlen); long index = source.indexOf((byte) 0); if (index == -1) throw new EOFException(); if (fhcrc) updateCrc(source.buffer(), 0, index + 1); source.skip(index + 1); long index = source.indexOf((byte) 0); if (index == -1) throw new EOFException(); if (fhcrc) updateCrc(source.buffer(), 0, index + 1); source.skip(index + 1); checkEqual("FHCRC", source.readShortLe(), (short) crc.getValue()); crc.reset();
private void consumeTrailer() throws IOException { // Read the eight-byte trailer. Confirm the body's CRC and size. // +---+---+---+---+---+---+---+---+ // | CRC32 | ISIZE | // +---+---+---+---+---+---+---+---+ checkEqual("CRC", source.readIntLe(), (int) crc.getValue()); checkEqual("ISIZE", source.readIntLe(), inflater.getTotalOut()); }
GzipSource gzippedResponseBody = null; try { gzippedResponseBody = new GzipSource(buffer.clone()); buffer = new Buffer(); buffer.writeAll(gzippedResponseBody); } finally { if (gzippedResponseBody != null) { gzippedResponseBody.close();
private void readTheList() throws IOException { byte[] publicSuffixListBytes; byte[] publicSuffixExceptionListBytes; InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE); if (resource == null) return; try (BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)))) { int totalBytes = bufferedSource.readInt(); publicSuffixListBytes = new byte[totalBytes]; bufferedSource.readFully(publicSuffixListBytes); int totalExceptionBytes = bufferedSource.readInt(); publicSuffixExceptionListBytes = new byte[totalExceptionBytes]; bufferedSource.readFully(publicSuffixExceptionListBytes); } synchronized (this) { this.publicSuffixListBytes = publicSuffixListBytes; this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes; } readCompleteLatch.countDown(); }
GzipSource gzippedResponseBody = null; try { gzippedResponseBody = new GzipSource(buffer.clone()); buffer = new Buffer(); buffer.writeAll(gzippedResponseBody); } finally { if (gzippedResponseBody != null) { gzippedResponseBody.close();
private Buffer gunzip(Buffer gzipped) throws IOException { Buffer result = new Buffer(); GzipSource source = new GzipSource(gzipped); while (source.read(result, Integer.MAX_VALUE) != -1) { } return result; }
&& "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding")) && HttpHeaders.hasBody(networkResponse)) { GzipSource responseBody = new GzipSource(networkResponse.body().source()); Headers strippedHeaders = networkResponse.headers().newBuilder() .removeAll("Content-Encoding")
GzipSource gzippedResponseBody = null; try { gzippedResponseBody = new GzipSource(buffer.clone()); buffer = new Buffer(); buffer.writeAll(gzippedResponseBody); } finally { if (gzippedResponseBody != null) { gzippedResponseBody.close();
try { Buffer result = new Buffer(); GzipSource source = new GzipSource(new Buffer().write(body)); while (source.read(result, Integer.MAX_VALUE) != -1) ; body = result.readByteArray(); } catch (IOException e) {
private void readTheList() throws IOException { byte[] publicSuffixListBytes; byte[] publicSuffixExceptionListBytes; InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE); if (resource == null) return; try (BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)))) { int totalBytes = bufferedSource.readInt(); publicSuffixListBytes = new byte[totalBytes]; bufferedSource.readFully(publicSuffixListBytes); int totalExceptionBytes = bufferedSource.readInt(); publicSuffixExceptionListBytes = new byte[totalExceptionBytes]; bufferedSource.readFully(publicSuffixExceptionListBytes); } synchronized (this) { this.publicSuffixListBytes = publicSuffixListBytes; this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes; } readCompleteLatch.countDown(); }
GzipSource gzipSource = new GzipSource(httpResponse.body() .source()); while (gzipSource.read(buffer, Integer.MAX_VALUE) != -1) {
&& "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding")) && HttpHeaders.hasBody(networkResponse)) { GzipSource responseBody = new GzipSource(networkResponse.body().source()); Headers strippedHeaders = networkResponse.headers().newBuilder() .removeAll("Content-Encoding")
if ("gzip".equalsIgnoreCase(headers.get("Content-Encoding"))) { gzippedLength = buffer.size(); try (GzipSource gzippedResponseBody = new GzipSource(buffer.clone())) { buffer = new Buffer(); buffer.writeAll(gzippedResponseBody);
@Test public void gunzipExhaustsSource() throws Exception { Buffer gzippedSource = new Buffer() .write(ByteString.decodeHex("1f8b08000000000000004b4c4a0600c241243503000000")); // 'abc' ExhaustableSource exhaustableSource = new ExhaustableSource(gzippedSource); BufferedSource gunzippedSource = Okio.buffer(new GzipSource(exhaustableSource)); assertEquals('a', gunzippedSource.readByte()); assertEquals('b', gunzippedSource.readByte()); assertEquals('c', gunzippedSource.readByte()); assertFalse(exhaustableSource.exhausted); assertEquals(-1, gunzippedSource.read(new Buffer(), 1)); assertTrue(exhaustableSource.exhausted); }
if ("gzip".equalsIgnoreCase(headers.get("Content-Encoding"))) { gzippedLength = buffer.size(); try (GzipSource gzippedResponseBody = new GzipSource(buffer.clone())) { buffer = new Buffer(); buffer.writeAll(gzippedResponseBody);
@Test public void gunzipThrowsIfSourceIsNotExhausted() throws Exception { Buffer gzippedSource = new Buffer() .write(ByteString.decodeHex("1f8b08000000000000004b4c4a0600c241243503000000")); // 'abc' gzippedSource.writeByte('d'); // This byte shouldn't be here! BufferedSource gunzippedSource = Okio.buffer(new GzipSource(gzippedSource)); assertEquals('a', gunzippedSource.readByte()); assertEquals('b', gunzippedSource.readByte()); assertEquals('c', gunzippedSource.readByte()); try { gunzippedSource.readByte(); fail(); } catch (IOException expected) { } }