Stigebil

Here, Hare, Here

Monthly Archives: November 2011


public static void tarGz(final List filesToCompress, final File destination) {
TarArchiveOutputStream tarOut = null;
byte[] buf = new byte[BUFFER_SIZE];
try {
tarOut = new TarArchiveOutputStream(
new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(destination))));
tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (File fileToCompress : filesToCompress) {
TarArchiveEntry entry = new TarArchiveEntry(fileToCompress.getName());
entry.setSize(fileToCompress.length());
tarOut.putArchiveEntry(entry);
FileInputStream input = new FileInputStream(fileToCompress);
int len;
while ((len = input.read(buf)) > 0) {
tarOut.write(buf, 0, len);
}

tarOut.closeArchiveEntry();
input.close();
}
tarOut.close();
} catch (IOException e) {
LOG.error("Could not tarGz file " + destination, e);
} finally {
IOUtils.closeQuietly(tarOut);
}
}

Design a site like this with WordPress.com
Get started