use of java.util.zip.DeflaterOutputStream in project dropwizard by dropwizard.
the class BiDiGzipHandlerTest method testDecompressDeflateRequestGzipIncompatible.
@Test
public void testDecompressDeflateRequestGzipIncompatible() throws Exception {
request.setMethod("POST");
request.setURI("/banner");
request.setHeader(HttpHeaders.CONTENT_ENCODING, "deflate");
request.setHeader(HttpHeaders.CONTENT_TYPE, PLAIN_TEXT_UTF_8);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DeflaterOutputStream deflate = new DeflaterOutputStream(baos)) {
Resources.copy(Resources.getResource("assets/new-banner.txt"), deflate);
}
request.setContent(baos.toByteArray());
gzipHandler.setInflateNoWrap(false);
HttpTester.Response response = HttpTester.parseResponse(servletTester.getResponses(request.generate()));
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContent()).isEqualTo("Banner has been updated");
}
use of java.util.zip.DeflaterOutputStream in project flink by apache.
the class GenericCsvInputFormatTest method createTempDeflateFile.
private FileInputSplit createTempDeflateFile(String content) throws IOException {
File tempFile = File.createTempFile("test_contents", "tmp.deflate");
tempFile.deleteOnExit();
DataOutputStream dos = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream(tempFile)));
dos.writeBytes(content);
dos.close();
return new FileInputSplit(0, new Path(tempFile.toURI().toString()), 0, tempFile.length(), new String[] { "localhost" });
}
use of java.util.zip.DeflaterOutputStream in project rest.li by linkedin.
the class TestStreamingCompression method testDeflateCompressor.
@Test
public void testDeflateCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new DeflateCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'c');
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream zlib = new DeflaterOutputStream(out);
IOUtils.write(origin, zlib);
zlib.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of java.util.zip.DeflaterOutputStream in project rest.li by linkedin.
the class TestStreamingCompression method testDeflateCompressor.
@Test
public void testDeflateCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new DeflateCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'c');
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream zlib = new DeflaterOutputStream(out);
IOUtils.write(origin, zlib);
zlib.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of java.util.zip.DeflaterOutputStream in project bazel by bazelbuild.
the class ProfilerTest method testUnsupportedProfilerRecord.
@Test
public void testUnsupportedProfilerRecord() throws Exception {
Path dataFile = cacheDir.getRelative("profile5.dat");
profiler.start(ProfiledTaskKinds.ALL, dataFile.getOutputStream(), "phase test", false, BlazeClock.instance(), BlazeClock.instance().nanoTime());
profiler.startTask(ProfilerTask.TEST, "outer task");
profiler.logEvent(ProfilerTask.EXCEPTION, "inner task");
profiler.completeTask(ProfilerTask.TEST);
profiler.startTask(ProfilerTask.SCANNER, "outer task 2");
profiler.logSimpleTask(Profiler.nanoTimeMaybe(), ProfilerTask.TEST, "inner task 2");
profiler.completeTask(ProfilerTask.SCANNER);
profiler.stop();
// Validate our test profile.
ProfileInfo info = ProfileInfo.loadProfile(dataFile);
info.calculateStats();
assertFalse(info.isCorruptedOrIncomplete());
assertEquals(2, info.getStatsForType(ProfilerTask.TEST, info.rootTasksById).count);
assertEquals(0, info.getStatsForType(ProfilerTask.UNKNOWN, info.rootTasksById).count);
// Now replace "TEST" type with something unsupported - e.g. "XXXX".
InputStream in = new InflaterInputStream(dataFile.getInputStream(), new Inflater(false), 65536);
byte[] buffer = new byte[60000];
int len = in.read(buffer);
in.close();
// Validate that file was completely decoded.
assertTrue(len < buffer.length);
String content = new String(buffer, ISO_8859_1);
int infoIndex = content.indexOf("TEST");
assertTrue(infoIndex > 0);
content = content.substring(0, infoIndex) + "XXXX" + content.substring(infoIndex + 4);
OutputStream out = new DeflaterOutputStream(dataFile.getOutputStream(), new Deflater(Deflater.BEST_SPEED, false), 65536);
out.write(content.getBytes(ISO_8859_1));
out.close();
// Validate that XXXX records were classified as UNKNOWN.
info = ProfileInfo.loadProfile(dataFile);
info.calculateStats();
assertFalse(info.isCorruptedOrIncomplete());
assertEquals(0, info.getStatsForType(ProfilerTask.TEST, info.rootTasksById).count);
assertEquals(1, info.getStatsForType(ProfilerTask.SCANNER, info.rootTasksById).count);
assertEquals(1, info.getStatsForType(ProfilerTask.EXCEPTION, info.rootTasksById).count);
assertEquals(2, info.getStatsForType(ProfilerTask.UNKNOWN, info.rootTasksById).count);
}
Aggregations