Пример #1
0
 @Test
 public void testGzipUnarchive() throws Exception {
   final File input = getFile("bla.tgz");
   final File output = new File(dir, "bla.tar");
   try (InputStream is = new FileInputStream(input)) {
     final CompressorInputStream in =
         new CompressorStreamFactory().createCompressorInputStream("gz", is);
     FileOutputStream out = null;
     try {
       out = new FileOutputStream(output);
       IOUtils.copy(in, out);
     } finally {
       if (out != null) {
         out.close();
       }
       in.close();
     }
   }
 }
Пример #2
0
  /** @see "https://issues.apache.org/jira/browse/COMPRESS-84" */
  @Test
  public void testCorruptedInput() throws Exception {
    InputStream in = null;
    OutputStream out = null;
    CompressorInputStream cin = null;
    try {
      in = new FileInputStream(getFile("bla.tgz"));
      out = new ByteArrayOutputStream();
      IOUtils.copy(in, out);
      in.close();
      out.close();

      final byte[] data = ((ByteArrayOutputStream) out).toByteArray();
      in = new ByteArrayInputStream(data, 0, data.length - 1);
      cin = new CompressorStreamFactory().createCompressorInputStream("gz", in);
      out = new ByteArrayOutputStream();

      try {
        IOUtils.copy(cin, out);
        fail("Expected an exception");
      } catch (final IOException ioex) {
        // the whole point of the test
      }

    } finally {
      if (out != null) {
        out.close();
      }
      if (cin != null) {
        cin.close();
      }
      if (in != null) {
        in.close();
      }
    }
  }