Package de.hsh.graja.util
Class Zip
java.lang.Object
de.hsh.graja.util.Zip
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn in-memory representation of a zip file's entry.static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFilesToExistingZip(File zipFile, Path baseDir, File[] entries) static booleanisZipFile(byte[] data) Checks, ifdatacan be read as a zip file.static booleanChecks, iffcan be read as a zip file.static booleanisZipFile(InputStream is) Checks, ifiscan be read as a zip file.static Zip.ZipResultUnzips the zip file "file" into the directory "dest"static byte[]unzipEntry(File file, String entry) Unzips the zip file "file" into the directory "dest"static Zip.ZipResultunzipInMemoryElements(byte[] input, List<Zip.ZipContentElement> output) static Zip.ZipResultZips the contents of dir2zip to the file dir2zip.getParent().resolve(dir2zip.getName(dir2zip.getNameCount()-1)+".zip" Zip entries are created as relative entries with respect to dir2zip's parent directory.static Zip.ZipResultZips the contents of dir2zip to the file located at toZipFile.static Zip.ZipResultZips the contents of dir2zip to the file located at toZipFile.static Zip.ZipResultzipInMemoryElements(List<Zip.ZipContentElement> source, OutputStream os) Read elements fromsourceand write them as a zip file toos.static Zip.ZipResultzipInMemorySingleFile(Zip.ZipContentElement source, OutputStream os) Read element fromsourceand write it as a zip file toos.
-
Constructor Details
-
Zip
public Zip()
-
-
Method Details
-
isZipFile
Checks, iffcan be read as a zip file.- Parameters:
f- the file- Returns:
- true, if can be read as a zip file.
-
isZipFile
Checks, ifiscan be read as a zip file.- Parameters:
is- the input stream- Returns:
- true, if can be read as a zip file.
-
isZipFile
public static boolean isZipFile(byte[] data) Checks, ifdatacan be read as a zip file.- Parameters:
data- the input data- Returns:
- true, if can be read as a zip file.
-
zipDir
Zips the contents of dir2zip to the file dir2zip.getParent().resolve(dir2zip.getName(dir2zip.getNameCount()-1)+".zip" Zip entries are created as relative entries with respect to dir2zip's parent directory.- Parameters:
dir2zip-- Throws:
IOException
-
zipDir
Zips the contents of dir2zip to the file located at toZipFile. Zip entries are created as relative entries with respect to dir2zip's parent directory.- Parameters:
dir2zip-toZipFile-- Throws:
IOException
-
zipDir
Zips the contents of dir2zip to the file located at toZipFile. Zip entries are created as relative entries with respect to baseDir.- Parameters:
dir2zip-baseDir-toZipFile-- Throws:
IOException
-
zipInMemorySingleFile
public static Zip.ZipResult zipInMemorySingleFile(Zip.ZipContentElement source, OutputStream os) throws IOException Read element fromsourceand write it as a zip file toos.- Parameters:
source-os-- Returns:
- Throws:
IOException
-
zipInMemoryElements
public static Zip.ZipResult zipInMemoryElements(List<Zip.ZipContentElement> source, OutputStream os) throws IOException Read elements fromsourceand write them as a zip file toos.- Parameters:
source-os-- Returns:
- Throws:
IOException
-
unzipInMemoryElements
public static Zip.ZipResult unzipInMemoryElements(byte[] input, List<Zip.ZipContentElement> output) throws IOException - Throws:
IOException
-
unzip
Unzips the zip file "file" into the directory "dest"- Parameters:
file- The zip filedestDir- Directory where the content of the zip file will be saved- Throws:
IOException- thrown, when unzip has not succeeded
-
unzipEntry
Unzips the zip file "file" into the directory "dest"- Parameters:
file- The zip fileentry- entry name- Throws:
IOException- thrown, when unzip has not succeeded
-
addFilesToExistingZip
public static void addFilesToExistingZip(File zipFile, Path baseDir, File[] entries) throws IOException - Throws:
IOException
-