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)
long
unGZip(File gzFile, File targetFile)
UnGunzips a given .gz filelong
unGZip(InputStream is, File target)
UnGunzips a given .gz streamvoid
unGZipUnTar(File tarGzFile, File targetDir)
Gunzips and Untars a given .tar.gz fileint
unzip(InputStream zipStream, String target)
This method extracts all entries of a zip-file.long
unzip(InputStream input, String entry, File target)
Extracts a specific entry inside a given zip streamint
unzip(String zipFile, String target)
This method extracts all entries of a zip-file.long
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 int unzip(String zipFile, String target) throws IOException
This method extracts all entries of a zip-file.- Parameters:
zipFile
- Path of the zip-file.target
- Path of the extracted files.- Returns:
- Number of extracted entries
- Throws:
IOException
- Error unpacking the zip
-
unzip
public int unzip(InputStream zipStream, String target) throws IOException
This method extracts all entries of a zip-file.- Parameters:
zipStream
- the zip contentstarget
- Path of the extracted files.- Returns:
- Number of extracted entries
- Throws:
IOException
- Error unpacking the zip
-
unzip
public long unzip(InputStream input, String entry, File target) throws IOException
Extracts a specific entry inside a given zip stream- Parameters:
input
- the stream of the zip fileentry
- name of the entry to extracttarget
- the file where to store the entry- Returns:
- number of written bytes
- Throws:
IOException
- Error unpacking the zip
-
unzipEntry
public long unzipEntry(File zipFile, String entry, File target) throws IOException
This method extracts a specific entry of a zip-file. https://github.com/srikanth-lingala/zip4j- Parameters:
zipFile
- File to read inside itentry
- The entry to be readtarget
- The extracted file- Returns:
- number of written bytes
- Throws:
IOException
- Error extracting the zip
-
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
-
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) throws IOException
Gunzips and Untars a given .tar.gz file- Parameters:
tarGzFile
- the .tar.gz filetargetDir
- the target folder to unpack to- Throws:
IOException
- An error processing the GZip or Tar
-
unGZip
public long unGZip(File gzFile, File targetFile) throws IOException
UnGunzips a given .gz file- Parameters:
gzFile
- the .gz filetargetFile
- the target file to unpack to- Returns:
- size of the written file
- Throws:
IOException
- Error processing the GZip
-
unGZip
public long unGZip(InputStream is, File target) throws IOException
UnGunzips a given .gz stream- Parameters:
is
- the .gz streamtarget
- the target file to unpack to- Returns:
- size of the written file
- Throws:
IOException
- Error processing the GZip
-
-