Package de.hsh.graja.util
Class Zip
java.lang.Object
de.hsh.graja.util.Zip
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An in-memory representation of a zip file's entry.static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addFilesToExistingZip
(File zipFile, Path baseDir, File[] entries) static boolean
isZipFile
(byte[] data) Checks, ifdata
can be read as a zip file.static boolean
Checks, iff
can be read as a zip file.static boolean
isZipFile
(InputStream is) Checks, ifis
can be read as a zip file.static Zip.ZipResult
Unzips 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.ZipResult
unzipInMemoryElements
(byte[] input, List<Zip.ZipContentElement> output) static Zip.ZipResult
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.static Zip.ZipResult
Zips the contents of dir2zip to the file located at toZipFile.static Zip.ZipResult
Zips the contents of dir2zip to the file located at toZipFile.static Zip.ZipResult
zipInMemoryElements
(List<Zip.ZipContentElement> source, OutputStream os) Read elements fromsource
and write them as a zip file toos
.static Zip.ZipResult
zipInMemorySingleFile
(Zip.ZipContentElement source, OutputStream os) Read element fromsource
and write it as a zip file toos
.
-
Constructor Details
-
Zip
public Zip()
-
-
Method Details
-
isZipFile
Checks, iff
can be read as a zip file.- Parameters:
f
- the file- Returns:
- true, if can be read as a zip file.
-
isZipFile
Checks, ifis
can 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, ifdata
can 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 fromsource
and 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 fromsource
and 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
-