-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Support for GNU tar format #9
Comments
Yeah, I met the problem of having my file name truncated to at most 100 characters. After some searching, I found another alternative that works fine with long file names: Commons-Compress import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
public class UnTarFile {
final static int BUFFER = 2048;
/**
* Command line arguments : argv[0]-----> Source tar.gz file. argv[1]----->
* DestarInation directory.
**/
public static void main(String[] args) throws IOException {
/** create a TarArchiveInputStream object. **/
FileInputStream fin = new FileInputStream(args[0]);
BufferedInputStream in = new BufferedInputStream(fin);
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn);
TarArchiveEntry entry = null;
/** Read the tar entries using the getNextEntry method **/
while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) {
System.out.println("Extracting: " + entry.getName());
/** If the entry is a directory, create the directory. **/
if (entry.isDirectory()) {
File f = new File(args[1] + entry.getName());
f.mkdirs();
}
/**
* If the entry is a file,write the decompressed file to the disk
* and close destination stream.
**/
else {
int count;
byte data[] = new byte[BUFFER];
FileOutputStream fos = new FileOutputStream(args[1]
+ entry.getName());
BufferedOutputStream dest = new BufferedOutputStream(fos,
BUFFER);
while ((count = tarIn.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.close();
}
}
/** Close the input stream **/
tarIn.close();
System.out.println("untar completed successfully!!");
}
} |
Hello,
As mentioned in #6, jtar is not fully compatible with the GNU tar format. As gnu tar finds use on popular linux distributions such as ubuntu, you may want to consider supporting it in the future. It is possible to create ustar format archives with the gnu tar tool, though it is not the default.
cheers
The text was updated successfully, but these errors were encountered: