예제 #1
0
  @Test
  public void testInteroperabilityWithGZIPInputStream() throws Exception {
    byte[] content;
    try (FileInputStream fis = new FileInputStream(getFile("test3.xml"))) {
      content = IOUtils.toByteArray(fis);
    }

    final ByteArrayOutputStream bout = new ByteArrayOutputStream();

    final GzipParameters parameters = new GzipParameters();
    parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
    parameters.setOperatingSystem(3);
    parameters.setFilename("test3.xml");
    parameters.setComment("Test file");
    parameters.setModificationTime(System.currentTimeMillis());
    final GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters);
    out.write(content);
    out.flush();
    out.close();

    final GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(bout.toByteArray()));
    final byte[] content2 = IOUtils.toByteArray(in);

    Assert.assertArrayEquals("uncompressed content", content, content2);
  }
예제 #2
0
 @Test
 public void testOverWrite() throws Exception {
   final GzipCompressorOutputStream out =
       new GzipCompressorOutputStream(new ByteArrayOutputStream());
   out.close();
   try {
     out.write(0);
     fail("IOException expected");
   } catch (final IOException e) {
     // expected
   }
 }