private static File uncompress(File compressedFile, File targetDirectory) {
File targetDir = null;
if( compressedFile.getName().endsWith(".tar.gz") ) {
try {
TarInputStream in = new TarInputStream(new GZIPInputStream(new FileInputStream(compressedFile)));
TarEntry e;
while( (e = in.getNextEntry()) != null ) {
if( e.isDirectory() ) {
File f = new File(targetDirectory,e.getName());
f.mkdirs();
if( targetDir == null ) {
targetDir = f;
}
} else {
File f = new File(targetDirectory,e.getName());
if( ! f.getParentFile().exists() ) {
f.getParentFile().mkdirs();
}
in.copyEntryContents(new FileOutputStream(f));
int m = e.getMode();
if( (m & OWNER_EXEC) == OWNER_EXEC
|| (m & GROUP_EXEC) == GROUP_EXEC
|| (m & OTHER_EXEC) == OTHER_EXEC ) {
f.setExecutable(true, false);
} else if( e.getLinkName() != null && e.getLinkName().trim().length() > 0 ) {
//TODO Handle symlinks
// System.err.println("A LINK: " + e.getLinkName());
}
}
}
in.close();
if( targetDir == null ) {
targetDir = new File(targetDirectory,"eclipse");
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else if( compressedFile.getName().endsWith(".zip") ) {
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(compressedFile));
ZipEntry e;
while( (e = in.getNextEntry()) != null ) {
if( e.isDirectory() ) {
File f = new File(targetDirectory,e.getName());
f.mkdirs();
if( targetDir == null ) {
targetDir = f;
}
} else {
File f = new File(targetDirectory,e.getName());
if( ! f.getParentFile().exists() ) {
f.getParentFile().mkdirs();
}
FileOutputStream out = new FileOutputStream(f);
byte[] buf = new byte[1024];
int l;
while( (l = in.read(buf, 0, 1024)) != -1 ) {
out.write(buf,0,l);
}
out.close();
}
in.closeEntry();
}
in.close();
if( targetDir == null ) {
targetDir = new File(targetDirectory,"eclipse");
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}