Ejemplo n.º 1
0
  @Test
  public void testMetadataRoundTrip() throws Exception {
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();

    final GzipParameters parameters = new GzipParameters();
    parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
    parameters.setModificationTime(123456000);
    parameters.setOperatingSystem(13);
    parameters.setFilename("test3.xml");
    parameters.setComment("Umlaute möglich?");
    try (GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters);
        FileInputStream fis = new FileInputStream(getFile("test3" + ".xml"))) {
      IOUtils.copy(fis, out);
    }

    final GzipCompressorInputStream input =
        new GzipCompressorInputStream(new ByteArrayInputStream(bout.toByteArray()));
    input.close();
    final GzipParameters readParams = input.getMetaData();
    assertEquals(Deflater.BEST_COMPRESSION, readParams.getCompressionLevel());
    assertEquals(123456000, readParams.getModificationTime());
    assertEquals(13, readParams.getOperatingSystem());
    assertEquals("test3.xml", readParams.getFilename());
    assertEquals("Umlaute möglich?", readParams.getComment());
  }
Ejemplo n.º 2
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);
  }