ZipUtil
public
class
ZipUtil
extends Object
java.lang.Object
|
↳ |
com.android.tradefed.util.ZipUtil
|
A helper class for compression-related operations
Summary
Public methods |
static
void
|
addToZip(ZipOutputStream out, File file, List<String> relativePathSegs)
Recursively adds given file and its contents to ZipOutputStream
|
static
void
|
closeZip(ZipFile zipFile)
Close an open ZipFile , ignoring any exceptions.
|
static
File
|
createZip(File dir, String name)
Utility method to create a temporary zip file containing the given directory and
all its contents.
|
static
File
|
createZip(File dir)
Utility method to create a temporary zip file containing the given directory and
all its contents.
|
static
File
|
createZip(List<File> files)
Utility method to create a temporary zip file containing the given files
|
static
File
|
createZip(List<File> files, String name)
Utility method to create a temporary zip file containing the given files.
|
static
void
|
createZip(List<File> files, File zipFile)
Utility method to create a zip file containing the given files
|
static
void
|
createZip(File dir, File zipFile)
Utility method to create a zip file containing the given directory and
all its contents.
|
static
File
|
extractFileFromZip(ZipFile zipFile, String filePath)
Utility method to extract one specific file from zip file into a tmp file
|
static
void
|
extractZip(ZipFile zipFile, File destDir)
Utility method to extract entire contents of zip file into given directory
|
static
File
|
extractZipToTemp(File zipFile, String nameHint)
Extract a zip file to a temp directory prepended with a string
|
static
void
|
gzipFile(File file, File gzipFile)
Helper method to create a gzipped version of a single file.
|
static
boolean
|
isZipFileValid(File zipFile, boolean thorough)
Utility method to verify that a zip file is not corrupt.
|
Public constructors
ZipUtil
public ZipUtil ()
Public methods
addToZip
public static void addToZip (ZipOutputStream out,
File file,
List<String> relativePathSegs)
Recursively adds given file and its contents to ZipOutputStream
Parameters |
out |
ZipOutputStream : the ZipOutputStream |
file |
File : the File to add to the stream |
relativePathSegs |
List : the relative path of file, including separators |
Throws |
IOException |
if failed to add file to zip
|
closeZip
public static void closeZip (ZipFile zipFile)
Close an open ZipFile
, ignoring any exceptions.
Parameters |
zipFile |
ZipFile : the file to close
|
createZip
public static File createZip (File dir,
String name)
Utility method to create a temporary zip file containing the given directory and
all its contents.
Parameters |
dir |
File : the directory to zip |
name |
String : the base name of the zip file created without the extension. |
Returns |
File |
a temporary zip File containing directory contents |
Throws |
IOException |
if failed to create zip file
|
createZip
public static File createZip (File dir)
Utility method to create a temporary zip file containing the given directory and
all its contents.
Parameters |
dir |
File : the directory to zip |
Returns |
File |
a temporary zip File containing directory contents |
Throws |
IOException |
if failed to create zip file
|
createZip
public static File createZip (List<File> files)
Utility method to create a temporary zip file containing the given files
Parameters |
files |
List : list of files to zip |
Returns |
File |
a temporary zip File containing directory contents |
Throws |
IOException |
if failed to create zip file
|
createZip
public static File createZip (List<File> files,
String name)
Utility method to create a temporary zip file containing the given files.
Parameters |
files |
List : list of files to zip |
name |
String : the base name of the zip file created without the extension. |
Returns |
File |
a temporary zip File containing directory contents |
Throws |
IOException |
if failed to create zip file
|
createZip
public static void createZip (List<File> files,
File zipFile)
Utility method to create a zip file containing the given files
Parameters |
files |
List : list of files to zip |
zipFile |
File : the zip file to create - it should not already exist |
Throws |
IOException |
if failed to create zip file
|
createZip
public static void createZip (File dir,
File zipFile)
Utility method to create a zip file containing the given directory and
all its contents.
Parameters |
dir |
File : the directory to zip |
zipFile |
File : the zip file to create - it should not already exist |
Throws |
IOException |
if failed to create zip file
|
public static File extractFileFromZip (ZipFile zipFile,
String filePath)
Utility method to extract one specific file from zip file into a tmp file
Parameters |
zipFile |
ZipFile : the ZipFile to extract |
filePath |
String : the filePath of to extract |
Returns |
File |
the File or null if not found
|
Throws |
IOException |
if failed to extract file |
public static void extractZip (ZipFile zipFile,
File destDir)
Utility method to extract entire contents of zip file into given directory
Parameters |
zipFile |
ZipFile : the ZipFile to extract |
destDir |
File : the local dir to extract file to |
Throws |
IOException |
if failed to extract file
|
public static File extractZipToTemp (File zipFile,
String nameHint)
Extract a zip file to a temp directory prepended with a string
Parameters |
zipFile |
File : the zip file to extract |
nameHint |
String : a prefix for the temp directory |
Returns |
File |
a File pointing to the temp directory
|
Throws |
IOException |
|
ZipException |
|
gzipFile
public static void gzipFile (File file,
File gzipFile)
Helper method to create a gzipped version of a single file.
Parameters |
file |
File : the original file |
gzipFile |
File : the file to place compressed contents in |
isZipFileValid
public static boolean isZipFileValid (File zipFile,
boolean thorough)
Utility method to verify that a zip file is not corrupt.
Parameters |
zipFile |
File : the File to check |
thorough |
boolean : Whether to attempt to fully extract the archive. If false , this
method will fail to detect CRC errors in a well-formed archive. |
Returns |
boolean |
false if the file appears to be corrupt; true otherwise
|
Throws |
IOException |
if the file could not be opened or read |