I don't think you understand. I want to make Tar archives straight from the system data.
Anyway, I decided to just deal with the 2GB file size limit. If anyone wants it, here is my code:
public static void createTarOfDirectory(String directoryPath, String tarPath) throws IOException {
FileOutputStream fOut = null;
BufferedOutputStream bOut = null;
TarArchiveOutputStream tOut = null;
try {
fOut = new FileOutputStream(new File(tarPath));
bOut = new BufferedOutputStream(fOut);
tOut = new TarArchiveOutputStream(bOut);
addFileToTar(tOut, directoryPath, "");
} finally {
tOut.finish();
tOut.close();
bOut.close();
fOut.close();
}
}
* Creates a tar entry for the path specified with a name built from the base passed in and the file/directory
private static void addFileToTar(TarArchiveOutputStream tOut, String path, String base) throws IOException {
File f = new File(path);
String entryName = base + f.getName();
TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
tOut.putArchiveEntry(tarEntry);
if (f.isFile()) {
IOUtils.copy(new FileInputStream(f), tOut);
tOut.closeArchiveEntry();
} else {
tOut.closeArchiveEntry();
File[] children = f.listFiles();
if (children != null) {
for (File child : children) {
addFileToTar(tOut, child.getAbsolutePath(), entryName + "/");
}
}
}
}
This uses the Apache Commons Compress library.