Esempio n. 1
0
 @Test
 public void testConcatenatedStreamsReadFirstOnly() throws Exception {
   final File input = getFile("multiple.bz2");
   try (InputStream is = new FileInputStream(input)) {
     try (CompressorInputStream in =
         new CompressorStreamFactory().createCompressorInputStream("bzip2", is)) {
       assertEquals('a', in.read());
       assertEquals(-1, in.read());
     }
   }
 }
Esempio n. 2
0
 @Test
 public void testConcatenatedStreamsReadFully() throws Exception {
   final File input = getFile("multiple.bz2");
   try (InputStream is = new FileInputStream(input)) {
     try (CompressorInputStream in = new BZip2CompressorInputStream(is, true)) {
       assertEquals('a', in.read());
       assertEquals('b', in.read());
       assertEquals(0, in.available());
       assertEquals(-1, in.read());
     }
   }
 }
Esempio n. 3
0
 @Test
 public void testCOMPRESS131() throws Exception {
   final File input = getFile("COMPRESS-131.bz2");
   try (InputStream is = new FileInputStream(input)) {
     try (CompressorInputStream in = new BZip2CompressorInputStream(is, true)) {
       int l = 0;
       while (in.read() != -1) {
         l++;
       }
       assertEquals(539, l);
     }
   }
 }
Esempio n. 4
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();
     }
   }
 }
Esempio n. 5
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();
      }
    }
  }