コード例 #1
0
  @Test
  public void codecTest() throws Exception {
    log.info("Codec: " + getCodec().toString());

    long fileLength = testFile.contentLength();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    StopWatch compressionStopWatch = new StopWatch();
    compressionStopWatch.start();
    Compressor compressor = getCodec();
    try (InputStream is = testFile.getInputStream()) {
      compressor.compress(is, bos);
    }
    compressionStopWatch.endAndLog("Compression");

    byte[] compressedData = bos.toByteArray();
    assertTrue(
        "Compressed file size should be less than original", compressedData.length < fileLength);

    InputStream bis = new ByteArrayInputStream(compressedData);
    ByteArrayOutputStream bos2 = new ByteArrayOutputStream();

    StopWatch decompressionStopWatch = new StopWatch();
    decompressionStopWatch.start();
    Decompressor decompressor = getCodec();
    decompressor.decompress(bis, bos2);
    decompressionStopWatch.endAndLog("Decompression");

    byte[] decompressedData = bos2.toByteArray();
    assertEquals(decompressedData.length, fileLength);

    try (InputStream is = testFile.getInputStream()) {
      assertTrue(IOUtils.contentEquals(is, new ByteArrayInputStream(bos2.toByteArray())));
    }
  }
コード例 #2
0
 public void displayInfo(Resource r) {
   System.out.println(r.getClass());
   try {
     System.out.println(r.getURL().getContent());
     System.out.println(r.contentLength());
     System.out.println(r.getFilename());
     System.out.println(r.isOpen());
     System.out.println(r.getInputStream().read());
     // System.out.println(r.);
   } catch (IOException e) {
     System.out.println("crazy error!");
   }
 }
コード例 #3
0
 @Override
 public long contentLength() throws IOException {
   return delegate.contentLength();
 }