Search in sources :

Example 41 with DeflaterOutputStream

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");
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 42 with DeflaterOutputStream

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" });
}
Also used : Path(org.apache.flink.core.fs.Path) FileInputSplit(org.apache.flink.core.fs.FileInputSplit) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DelimitedInputFormatTest.createTempFile(org.apache.flink.api.common.io.DelimitedInputFormatTest.createTempFile) File(java.io.File)

Example 43 with DeflaterOutputStream

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);
}
Also used : DeflateCompressor(com.linkedin.r2.filter.compression.streaming.DeflateCompressor) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 44 with DeflaterOutputStream

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);
}
Also used : DeflateCompressor(com.linkedin.r2.filter.compression.streaming.DeflateCompressor) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 45 with DeflaterOutputStream

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);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Deflater(java.util.zip.Deflater) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStream(java.io.OutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) Inflater(java.util.zip.Inflater) Test(org.junit.Test)

Aggregations

DeflaterOutputStream (java.util.zip.DeflaterOutputStream)76 ByteArrayOutputStream (java.io.ByteArrayOutputStream)50 Deflater (java.util.zip.Deflater)25 IOException (java.io.IOException)24 OutputStream (java.io.OutputStream)13 InflaterInputStream (java.util.zip.InflaterInputStream)9 DataOutputStream (java.io.DataOutputStream)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BufferedOutputStream (java.io.BufferedOutputStream)3 EOFException (java.io.EOFException)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 ImageException (cbit.image.ImageException)2 DeflateCompressor (com.linkedin.r2.filter.compression.streaming.DeflateCompressor)2 StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 PipedInputStream (java.io.PipedInputStream)2