Search Java Code Snippets


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





Java - Code Samples

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

    public void shouldUseSpecifiedEncodingWhenReadingGNULongNames()

throws Exception {

final ByteArrayOutputStream bos = new ByteArrayOutputStream();

final String encoding = CharsetNames.UTF_16;

final String name = "1234567890123456789012345678901234567890123456789"

+ "01234567890123456789012345678901234567890123456789"

+ "01234567890u00e4";

final TarArchiveOutputStream tos =

new TarArchiveOutputStream(bos, encoding);

tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

TarArchiveEntry t = new TarArchiveEntry(name);

t.setSize(1);

tos.putArchiveEntry(t);

tos.write(30);

tos.closeArchiveEntry();

tos.close();

final byte[] data = bos.toByteArray();

final ByteArrayInputStream bis = new ByteArrayInputStream(data);

final TarArchiveInputStream tis =

new TarArchiveInputStream(bis, encoding);

t = tis.getNextTarEntry();

assertEquals(name, t.getName());

tis.close();

}


   Like      Feedback      org.apache.commons.compress.archivers.tar.TarArchiveOutputStream



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