Package com.cmobilecom.af.util
Class ZipUtil
- java.lang.Object
-
- com.cmobilecom.af.util.ZipUtil
-
public class ZipUtil extends java.lang.Object
Zip/Unzip Utility- Since:
- 1.2
-
-
Constructor Summary
Constructors Constructor Description ZipUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addToZip(java.io.File srcDir, java.io.FilenameFilter filter, java.lang.String namePrefix, java.util.zip.ZipOutputStream zos)
Add all the files under the directory to the zip streamstatic void
addToZip(java.io.File file, java.lang.String entryName, java.util.zip.ZipOutputStream zos)
Add a file to the zipstatic java.io.InputStream
getEntryInputStream(java.io.File zipFile, java.lang.String entryName)
Get the inputStream of an entry in a zip file.static void
unTarGzip(java.io.File tarGzFile, java.io.File targetDir, NameMapper nameMapper, Progress progress)
Decompress and untar the tar.gz file to the specified directory.static void
unzip(java.io.File zipFile, java.io.File targetDir, NameMapper nameMapper)
Unzip a zip file to the specified directory.static void
unzip(java.io.File zipFile, java.io.File targetDir, NameMapper nameMapper, Progress progress)
Unzip a zip file to the specified directory.static void
unzip(java.io.InputStream zipFileInputStream, java.io.File targetDir, NameMapper nameMapper)
Unzip a zip file to the specified directory.static void
zip(java.io.File srcDir, java.io.FilenameFilter filter, java.lang.String namePrefix, java.io.File targetZipFile)
Zip all the files under the directory.
-
-
-
Method Detail
-
unzip
public static void unzip(java.io.File zipFile, java.io.File targetDir, NameMapper nameMapper) throws java.io.IOException
Unzip a zip file to the specified directory. If the target directory does not exist, it will be created.- Parameters:
zipFile
- zip filetargetDir
- target directory to unzip filenameMapper
- entry name mapper that is used to change file path name.- Throws:
java.io.IOException
- throw if any IO error occurs
-
unzip
public static void unzip(java.io.InputStream zipFileInputStream, java.io.File targetDir, NameMapper nameMapper) throws java.io.IOException
Unzip a zip file to the specified directory. If the target directory does not exist, it will be created.- Parameters:
zipFileInputStream
- zip file inputStreamtargetDir
- target directory to unzip filenameMapper
- entry name mapper that is used to change file path name.- Throws:
java.io.IOException
- throw if any IO error occurs
-
unzip
public static void unzip(java.io.File zipFile, java.io.File targetDir, NameMapper nameMapper, Progress progress) throws java.io.IOException
Unzip a zip file to the specified directory. If the target directory does not exist, it will be created.- Parameters:
zipFile
- zip filetargetDir
- target directory to unzip filenameMapper
- entry name mapper that is used to change file path name.progress
- the Progress object that receives progressing messages- Throws:
java.io.IOException
- throw if any IO error occurs
-
getEntryInputStream
public static java.io.InputStream getEntryInputStream(java.io.File zipFile, java.lang.String entryName) throws java.io.IOException
Get the inputStream of an entry in a zip file. The caller of this method is responsible for closing the inputStream.- Parameters:
zipFile
- zip fileentryName
- entry name- Returns:
- InputStream instance. return null if the entry is not found in the zip
- Throws:
java.io.IOException
- throw if an IO error occurs
-
zip
public static void zip(java.io.File srcDir, java.io.FilenameFilter filter, java.lang.String namePrefix, java.io.File targetZipFile) throws java.io.IOException
Zip all the files under the directory.- Parameters:
srcDir
- the directory to zipfilter
- file name filternamePrefix
- the prefix to prepend to all entry namestargetZipFile
- the zip file to create- Throws:
java.io.IOException
- throw if any IO error occurs
-
addToZip
public static void addToZip(java.io.File file, java.lang.String entryName, java.util.zip.ZipOutputStream zos) throws java.io.IOException
Add a file to the zip- Parameters:
file
- the file to addentryName
- the entry name of the file in the zipzos
- zip outputStream- Throws:
java.io.IOException
- throw if an IO error occurs
-
addToZip
public static void addToZip(java.io.File srcDir, java.io.FilenameFilter filter, java.lang.String namePrefix, java.util.zip.ZipOutputStream zos) throws java.io.IOException
Add all the files under the directory to the zip stream- Parameters:
srcDir
- directory under which files are to be added, including sub directories.filter
- name filternamePrefix
- the prefix to prepend to all entry nameszos
- zip output stream- Throws:
java.io.IOException
- throw if any IO error occurs
-
unTarGzip
public static void unTarGzip(java.io.File tarGzFile, java.io.File targetDir, NameMapper nameMapper, Progress progress) throws java.io.IOException
Decompress and untar the tar.gz file to the specified directory. If the target directory does not exist, it will be created.- Parameters:
tarGzFile
- tar gzip filetargetDir
- target directory to unzip filenameMapper
- entry name mapper that is used to change file path name.progress
- if not null, show processing progress- Throws:
java.io.IOException
- throw if any IO error occurs
-
-