Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#IOUtils.copy' - 7 code snippet(s) found

 Sample 1. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.ArchiveEntry

    private void addArchiveEntry(final ArchiveOutputStream out, final String filename, final File infile)

throws IOException, FileNotFoundException {

final ArchiveEntry entry = out.createArchiveEntry(infile, filename);

out.putArchiveEntry(entry);

IOUtils.copy(new FileInputStream(infile), out);

out.closeArchiveEntry();

archiveList.add(filename);

}


   Like      Feedback      org.apache.commons.compress.archivers.ArchiveEntry


 Sample 2. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

    private void testZipStreamWithImplodeCompression(final String filename, final String entryName) throws IOException {

final ZipArchiveInputStream zin = new ZipArchiveInputStream(new FileInputStream(new File(filename)));

final ZipArchiveEntry entry = zin.getNextZipEntry();

assertEquals("entry name", entryName, entry.getName());

assertTrue("entry can't be read", zin.canReadEntryData(entry));

assertEquals("method", ZipMethod.IMPLODING.getCode(), entry.getMethod());



final InputStream bio = new BoundedInputStream(zin, entry.getSize());



final ByteArrayOutputStream bout = new ByteArrayOutputStream();

final CheckedOutputStream out = new CheckedOutputStream(bout, new CRC32());

IOUtils.copy(bio, out);



out.flush();



assertEquals("CRC32", entry.getCrc(), out.getChecksum().getValue());

}


   Like      Feedback      org.apache.commons.compress.archivers.zip.ZipArchiveInputStream


 Sample 3. Code Sample / Example / Snippet of org.apache.commons.compress.compressors.CompressorInputStream

    public void testBzip2Unarchive() throws Exception {

final File input = getFile("bla.txt.bz2");

final File output = new File(dir, "bla.txt");

final InputStream is = new FileInputStream(input);

final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is);

final FileOutputStream os = new FileOutputStream(output);

IOUtils.copy(in, os);

is.close();

os.close();

}


   Like      Feedback      org.apache.commons.compress.compressors.CompressorInputStream


 Sample 4. Code Sample / Example / Snippet of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream

    private void testExtraFlags(final int compressionLevel, final int flag) throws Exception {

final FileInputStream fis = new FileInputStream(getFile("test3.xml"));

byte[] content;

try {

content = IOUtils.toByteArray(fis);

} finally {

fis.close();

}



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]);

}


   Like      Feedback      org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Code Sample / Example / Snippet of org.apache.commons.compress.compressors.deflate.DeflateParameters

    public void testRawDeflateCreation()  throws Exception {

final File input = getFile("test1.xml");

final File output = new File(dir, "test1.xml.deflate");

final OutputStream out = new FileOutputStream(output);

try {

final DeflateParameters params = new DeflateParameters();

params.setWithZlibHeader(false);

final CompressorOutputStream cos = new DeflateCompressorOutputStream(out, params);

try {

IOUtils.copy(new FileInputStream(input), cos);

} finally {

cos.close();

}

} finally {

out.close();

}

}


   Like      Feedback      org.apache.commons.compress.compressors.deflate.DeflateParameters


 Sample 6. Code Sample / Example / Snippet of org.apache.commons.compress.compressors.snappy.FramedSnappyCompressorInputStream

    public void testRemainingChunkTypes() throws Exception {

final FileInputStream isSz = new FileInputStream(getFile("mixed.txt.sz"));

final ByteArrayOutputStream out = new ByteArrayOutputStream();

try {

final FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(isSz);

IOUtils.copy(in, out);

out.close();

} finally {

isSz.close();

}



assertArrayEquals(new byte[] { '1', '2', '3', '4',

'5', '6', '7', '8', '9',

'5', '6', '7', '8', '9',

'5', '6', '7', '8', '9',

'5', '6', '7', '8', '9',

'5', '6', '7', '8', '9', 10,

'1', '2', '3', '4',

'1', '2', '3', '4',

}, out.toByteArray());

}


   Like      Feedback      org.apache.commons.compress.compressors.snappy.FramedSnappyCompressorInputStream


 Sample 7. GunZip file using Apache Commons


   public void testGzipCreation() throws Exception {
final File input = getFile("test1.xml");
final File output = new File(dir, "test1.xml.gz");
final OutputStream out = new FileOutputStream(output);
try {
final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz", out);
try {
IOUtils.copy(new FileInputStream(input), cos);
} finally {
cos.close();
}
} finally {
out.close();
}
}

   Like      Feedback     Zip file using Apache Commons   Compress file using Apache Commons   GunZip file using Apache Commons  Code Sample / Example / Snippet of org.apache.commons.compress.compressors.CompressorOutputStream  IOUtils.copy



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner