Exemplo n.º 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);
  }
Exemplo n.º 2
0
  private void testExtraFlags(final int compressionLevel, final int flag) 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(compressionLevel);
    final GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters);
    IOUtils.copy(new ByteArrayInputStream(content), out);
    out.flush();
    out.close();

    assertEquals("extra flags (XFL)", flag, bout.toByteArray()[8]);
  }