* @param bundle Compressed Bundle file
* @param path
* @param fileName
*/
private void untar ( InputStream bundle, String path, String fileName ) {
TarEntry entry;
TarInputStream inputStream = null;
FileOutputStream outputStream = null;
try {
//Clean the bundler folder if exist to clean dirty data
String previousFolderPath = path.replace(fileName, "");
File previousFolder = new File(previousFolderPath);
if(previousFolder.exists()){
FileUtils.cleanDirectory(previousFolder);
}
// get a stream to tar file
InputStream gstream = new GZIPInputStream( bundle );
inputStream = new TarInputStream( gstream );
// For each entry in the tar, extract and save the entry to the file
// system
while ( null != (entry = inputStream.getNextEntry()) ) {
// for each entry to be extracted
int bytesRead;
String pathWithoutName = path.substring( 0,
path.indexOf( fileName ) );
// if the entry is a directory, create the directory
if ( entry.isDirectory() ) {
File fileOrDir = new File( pathWithoutName + entry.getName() );
fileOrDir.mkdir();
continue;
}
// write to file
byte[] buf = new byte[1024];
outputStream = new FileOutputStream( pathWithoutName
+ entry.getName() );
while ( (bytesRead = inputStream.read( buf, 0, 1024 )) > -1 )
outputStream.write( buf, 0, bytesRead );
try {
if ( null != outputStream ) {
outputStream.close();