This post originated from an RSS feed registered with Java Buzz
by Chris Winters.
Original Post: Creating gzipped archives from Java
Feed Title: cwinters.com
Feed URL: http://www.cwinters.com/search/registrar.php?domain=jroller.com®istrar=sedopark
Feed Description: Chris Winters on Java, programming and technology, usually in that order.
Using the Javatar library and the standard GZIP output stream you can create gzipped tarballs pretty easily. Since the Javatar library doesn't include any examples of creating an archive and you can spend a while spinning your wheels about how to most easily do this, here you go:
File destArchive = new File( "somefile.tar.gz" );
TarArchive archive = new TarArchive(
new GZIPOutputStream( new FileOutputStream( destArchive ) )
);
// assume we've got a collection of 'someFiles' from somewhere
for ( Iterator it = someFiles.iterator(); it.hasNext(); )
{
File recordFile = (File)it.next();
TarEntry entry = new TarEntry( recordFile );
entry.setName( recordFile.getName() ); // no leading dir info
archive.writeEntry( entry, false );
}
archive.closeArchive();