TarUtil

public class TarUtil
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.TarUtil


Utility to manipulate a tar file. It wraps the commons-compress in order to provide tar support.

Summary

Public constructors

TarUtil()

Public methods

static void extractAndLog(ITestLogger listener, File targzFile, String baseName)

Helper to extract and log to the reporters a tar gz file and its content

static File extractTarGzipToTemp(File targzFile, String nameHint)

Untar and ungzip a tar.gz file to a temp directory.

static File gzip(File inputFile)

Utility function to gzip (.gz) a file.

static boolean isGzip(File file)

Determine whether a file is a gzip.

static File unGzip(File inputFile, File outputDir)

UnGZip a file: a tar.gz file will become a tar file.

static unTar(File inputFile, File outputDir)

Untar a tar file into a directory.

static unTar(File inputFile, File outputDir, fileNames)

Untar a tar file into a directory.

Public constructors

TarUtil

public TarUtil ()

Public methods

extractAndLog

public static void extractAndLog (ITestLogger listener, 
                File targzFile, 
                String baseName)

Helper to extract and log to the reporters a tar gz file and its content

Parameters
listener ITestLogger: the ITestLogger where to log the files.

targzFile File: the tar.gz ERROR(/File) that needs its content log.

baseName String: the base name under which the files will be found.

extractTarGzipToTemp

public static File extractTarGzipToTemp (File targzFile, 
                String nameHint)

Untar and ungzip a tar.gz file to a temp directory.

Parameters
targzFile File: the tar.gz file to extract.

nameHint String: the prefix for the temp directory.

Returns
File the temp directory.

Throws
FileNotFoundException

gzip

public static File gzip (File inputFile)

Utility function to gzip (.gz) a file. the .gz extension will be added to base file name.

Parameters
inputFile File: the ERROR(/File) to be gzipped.

Returns
File the gzipped file.

isGzip

public static boolean isGzip (File file)

Determine whether a file is a gzip.

Parameters
file File: the file to check.

Returns
boolean whether the file is a gzip.

Throws
if the file could not be read.

unGzip

public static File unGzip (File inputFile, 
                File outputDir)

UnGZip a file: a tar.gz file will become a tar file.

Parameters
inputFile File: The ERROR(/File) to ungzip

outputDir File: The directory where to put the ungzipped file.

Returns
File a ERROR(/File) pointing to the ungzipped file.

Throws
FileNotFoundException

unTar

public static  unTar (File inputFile, 
                File outputDir)

Untar a tar file into a directory. tar.gz file needs to be unGzip(File, File) first.

Parameters
inputFile File: The tar file to extract

outputDir File: the directory where to put the extracted files.

Returns
The list of ERROR(/File) untarred.

Throws
FileNotFoundException

unTar

public static  unTar (File inputFile, 
                File outputDir, 
                 fileNames)

Untar a tar file into a directory. tar.gz file needs to be unGzip(File, File) first.

Parameters
inputFile File: The tar file to extract

outputDir File: the directory where to put the extracted files.

fileNames : the files to be extracted from the tar.

Returns
The list of ERROR(/File) untarred.

Throws
FileNotFoundException