use of java.util.zip.GZIPInputStream in project robovm by robovm.
the class GZIPInputStreamTest method gunzip.
public static byte[] gunzip(byte[] bytes) throws IOException {
InputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
in.close();
return out.toByteArray();
}
use of java.util.zip.GZIPInputStream in project robovm by robovm.
the class GZIPInputStreamTest method testSkip.
/** http://b/3042574 GzipInputStream.skip() causing CRC failures */
public void testSkip() throws IOException {
byte[] data = new byte[1024 * 1024];
byte[] gzipped = GZIPOutputStreamTest.gzip(data);
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(gzipped));
long totalSkipped = 0;
long count;
do {
count = in.skip(Long.MAX_VALUE);
totalSkipped += count;
} while (count > 0);
assertEquals(data.length, totalSkipped);
in.close();
}
use of java.util.zip.GZIPInputStream in project robovm by robovm.
the class OldAndroidGZIPStreamTest method scanGZIP.
static void scanGZIP(ByteArrayInputStream bytesIn) throws IOException {
GZIPInputStream in = new GZIPInputStream(bytesIn);
try {
ByteArrayOutputStream contents = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int len, totalLen = 0;
while ((len = in.read(buf)) > 0) {
contents.write(buf, 0, len);
totalLen += len;
}
assertEquals(totalLen, 128 * 1024);
} finally {
in.close();
}
}
use of java.util.zip.GZIPInputStream in project spring-boot by spring-projects.
the class SampleTomcatApplicationTests method testCompression.
@Test
public void testCompression() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Accept-Encoding", "gzip");
HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders);
ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()));
try {
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World");
} finally {
inflater.close();
}
}
use of java.util.zip.GZIPInputStream in project spring-boot by spring-projects.
the class SampleJettyApplicationTests method testCompression.
@Test
public void testCompression() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Accept-Encoding", "gzip");
HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders);
ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()));
try {
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World");
} finally {
inflater.close();
}
}
Aggregations