Package de.hsh.graja.util
Class Zip
- java.lang.Object
-
- de.hsh.graja.util.Zip
-
public class Zip extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Zip.ZipContentElement
An in-memory representation of a zip file's entry.static class
Zip.ZipResult
-
Constructor Summary
Constructors Constructor Description Zip()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addFilesToExistingZip(File zipFile, Path baseDir, File[] entries)
static boolean
isZipFile(byte[] data)
Checks, ifdata
can be read as a zip file.static boolean
isZipFile(File f)
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
unzip(File file, File destDir)
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
zipDir(Path dir2zip)
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
zipDir(Path dir2zip, String toZipFile)
Zips the contents of dir2zip to the file located at toZipFile.static Zip.ZipResult
zipDir(Path dir2zip, Path baseDir, String toZipFile)
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
.
-
-
-
Method Detail
-
isZipFile
public static boolean isZipFile(File f)
Checks, iff
can be read as a zip file.- Parameters:
f
- the file- Returns:
- true, if can be read as a zip file.
-
isZipFile
public static boolean isZipFile(InputStream is)
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
public static Zip.ZipResult zipDir(Path dir2zip) throws IOException
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
public static Zip.ZipResult zipDir(Path dir2zip, String toZipFile) throws IOException
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
public static Zip.ZipResult zipDir(Path dir2zip, Path baseDir, String toZipFile) throws IOException
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
public static Zip.ZipResult unzip(File file, File destDir) throws IOException
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
public static byte[] unzipEntry(File file, String entry) throws IOException
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
-
-