Package com.logicaldoc.util.io
Class ZipUtil
- java.lang.Object
-
- com.logicaldoc.util.io.ZipUtil
-
public class ZipUtil extends Object
This class is for handling with zip-files.- Version:
- 4.0
- Author:
- Marco Meschieri - LogicalDOC
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addEntry(File zip, String entry, InputStream content)
byte[]
getEntryBytes(File zipFile, String entry)
Read the entry inside the file zip resource.String
getEntryContent(File zip, String entry)
InputStream
getEntryStream(File zipFile, String entry)
Read the entry inside the file zip resource.String
getFileNameCharset()
List<String>
listEntries(File zipFile)
List<ZipEntry>
listZipEntries(File zipFile)
void
setFileNameCharset(String fileNameCharset)
void
unGZip(File gzFile, File targetFile)
UnGunzips a given .gz filevoid
unGZip(InputStream gzStream, File targetFile)
UnGunzips a given .gz streamvoid
unGZipUnTar(File tarGzFile, File targetDir)
Gunzips and Untars a given .tar.gz fileboolean
unzip(String zipFile, String target)
This method extracts all entries of a zip-file.void
unzipEntry(File zipFile, String entry, File target)
This method extracts a specific entry of a zip-file.void
zipFile(File src, File dest)
Compress a single filevoid
zipFolder(File inFolder, File outFile)
Zips a folder into a .zip archive
-
-
-
Constructor Detail
-
ZipUtil
public ZipUtil()
-
ZipUtil
public ZipUtil(String charset)
-
-
Method Detail
-
unzip
public boolean unzip(String zipFile, String target)
This method extracts all entries of a zip-file.- Parameters:
zipFile
- Path of the zip-file.target
- Path of the extracted files.- Returns:
- True if successfully extracted.
-
getEntryBytes
public byte[] getEntryBytes(File zipFile, String entry)
Read the entry inside the file zip resource.- Parameters:
zipFile
- File to read inside itentry
- The entry to be read- Returns:
- The bytes of the entry
-
unzipEntry
public void unzipEntry(File zipFile, String entry, File target)
This method extracts a specific entry of a zip-file.- Parameters:
zipFile
- File to read inside itentry
- The entry to be readtarget
- The extracted file
-
getEntryStream
public InputStream getEntryStream(File zipFile, String entry)
Read the entry inside the file zip resource.- Parameters:
zipFile
- File to read inside itentry
- The entry to be read- Returns:
- The stream of the entry
-
getEntryContent
public String getEntryContent(File zip, String entry) throws FileNotFoundException, IOException
- Throws:
FileNotFoundException
IOException
-
addEntry
public static void addEntry(File zip, String entry, InputStream content)
-
zipFile
public void zipFile(File src, File dest)
Compress a single file- Parameters:
src
- The source filedest
- The destination archive file
-
zipFolder
public void zipFolder(File inFolder, File outFile)
Zips a folder into a .zip archive- Parameters:
inFolder
- the folder to compressoutFile
- the zip file
-
getFileNameCharset
public String getFileNameCharset()
-
setFileNameCharset
public void setFileNameCharset(String fileNameCharset)
-
unGZipUnTar
public void unGZipUnTar(File tarGzFile, File targetDir)
Gunzips and Untars a given .tar.gz file- Parameters:
tarGzFile
- the .tar.gz filetargetDir
- the target folder to unpack to
-
unGZip
public void unGZip(File gzFile, File targetFile)
UnGunzips a given .gz file- Parameters:
gzFile
- the .gz filetargetFile
- the target file to unpack to
-
unGZip
public void unGZip(InputStream gzStream, File targetFile)
UnGunzips a given .gz stream- Parameters:
gzStream
- the .gz streamtargetFile
- the target file to unpack to
-
-