Package org.nuxeo.common.utils
Class ZipUtils
java.lang.Object
org.nuxeo.common.utils.ZipUtils
- Author:
- bstefanescu
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
_putDirectoryEntry
(String entryName, ZipOutputStream out) static void
_putFileEntry
(File file, String entryName, ZipOutputStream out) static void
_zip
(File[] files, ZipOutputStream out, String prefix) static void
_zip
(String entryName, File file, ZipOutputStream out) static void
_zip
(String entryName, InputStream in, ZipOutputStream out) static byte[]
getEntryContentAsBytes
(File file, String entryName) Deprecated.since 10.1 (unused and fails to close a ZipFile)static byte[]
getEntryContentAsBytes
(InputStream stream, String searchedEntryName) static byte[]
getEntryContentAsBytes
(URL url, String entryName) static InputStream
getEntryContentAsStream
(File file, String entryName) Deprecated.since 10.1 (unused and fails to close a ZipFile)static InputStream
getEntryContentAsStream
(InputStream stream, String entryName) static InputStream
getEntryContentAsStream
(URL url, String entryName) static String
getEntryContentAsString
(File file, String entryName) Deprecated.since 10.1 (unused and fails to close a ZipFile)static String
getEntryContentAsString
(InputStream stream, String searchedEntryName) static String
getEntryContentAsString
(URL url, String entryName) getEntryNames
(File file) Lists the entries on the zip file.getEntryNames
(InputStream stream) getEntryNames
(URL url) static boolean
Checks if a zip file contains a specified entry name.static boolean
hasEntry
(InputStream stream, String entryName) static boolean
static boolean
isValid
(InputStream stream) Checks if the content of theInputStream
is a valid zip.protected static String
normalizePrefix
(String prefix) static void
static void
unzip
(File zip, File dir, PathFilter filter) static void
unzip
(InputStream zipStream, File dir) static void
static void
unzip
(String prefix, File zip, File dir, PathFilter filter) static void
unzip
(String prefix, InputStream zipStream, File dir) static void
static void
unzip
(String prefix, ZipInputStream in, File dir) static void
unzip
(String prefix, ZipInputStream in, File dir, PathFilter filter) static void
static void
unzip
(ZipInputStream in, File dir) static void
unzip
(ZipInputStream in, File dir, PathFilter filter) static void
unzipIgnoreDirs
(InputStream zipStream, File dir) static void
unzipIgnoreDirs
(ZipInputStream in, File dir) static void
static void
static void
zip
(File[] files, OutputStream out, String prefix) static void
static void
static void
zip
(File file, OutputStream out, String prefix) static void
zipFilesUsingPrefix
(String prefix, File[] files, OutputStream out)
-
Method Details
-
_putDirectoryEntry
- Throws:
IOException
-
_putFileEntry
public static void _putFileEntry(File file, String entryName, ZipOutputStream out) throws IOException - Throws:
IOException
-
_zip
- Throws:
IOException
-
_zip
- Throws:
IOException
-
_zip
- Throws:
IOException
-
zip
- Throws:
IOException
-
normalizePrefix
- Returns:
- the empty string if prefix is null or empty, otherwise append a '/' at the end if needed
-
zip
- Throws:
IOException
-
zip
- Throws:
IOException
-
zip
- Throws:
IOException
-
zip
- Throws:
IOException
-
zip
- Throws:
IOException
-
zipFilesUsingPrefix
public static void zipFilesUsingPrefix(String prefix, File[] files, OutputStream out) throws IOException - Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzipIgnoreDirs
- Throws:
IOException
-
unzipIgnoreDirs
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
- Throws:
IOException
-
unzip
public static void unzip(String prefix, ZipInputStream in, File dir, PathFilter filter) throws IOException - Throws:
IOException
-
getEntryContentAsStream
@Deprecated public static InputStream getEntryContentAsStream(File file, String entryName) throws IOException Deprecated.since 10.1 (unused and fails to close a ZipFile)Unzip directly the entry. The returned InputStream has to be closed.- Parameters:
file
- the source fileentryName
- the entry name that has to be extracted- Returns:
- the input stream of the desired entry - has to be closed by the caller, or null if not found
- Throws:
IOException
-
getEntryContentAsString
@Deprecated public static String getEntryContentAsString(File file, String entryName) throws IOException Deprecated.since 10.1 (unused and fails to close a ZipFile)Unzip directly the entry.- Parameters:
file
- the source fileentryName
- the entry name that has to be extracted- Returns:
- the String content of the entry with name entryName
- Throws:
IOException
-
getEntryContentAsBytes
@Deprecated public static byte[] getEntryContentAsBytes(File file, String entryName) throws IOException Deprecated.since 10.1 (unused and fails to close a ZipFile)Unzips directly the entry.- Parameters:
file
- the source fileentryName
- the entry name that has to be extracted- Returns:
- The byte array content of the entry with name entryName
- Throws:
IOException
-
getEntryNames
Lists the entries on the zip file.- Parameters:
file
- The zip file- Returns:
- The list of entries
- Throws:
IOException
-
hasEntry
Checks if a zip file contains a specified entry name.- Parameters:
file
- the zip fileentryName
- The content to be checked- Returns:
- True if the file contains entryName. False otherwise
- Throws:
IOException
-
getEntryContentAsStream
public static InputStream getEntryContentAsStream(InputStream stream, String entryName) throws IOException - Throws:
IOException
-
getEntryContentAsString
public static String getEntryContentAsString(InputStream stream, String searchedEntryName) throws IOException - Throws:
IOException
-
getEntryContentAsBytes
public static byte[] getEntryContentAsBytes(InputStream stream, String searchedEntryName) throws IOException - Throws:
IOException
-
getEntryNames
- Throws:
IOException
-
hasEntry
- Throws:
IOException
-
getEntryContentAsStream
- Throws:
IOException
-
getEntryContentAsString
- Throws:
IOException
-
getEntryContentAsBytes
- Throws:
IOException
-
getEntryNames
- Throws:
IOException
-
hasEntry
- Throws:
IOException
-
isValid
Checks if the content of theInputStream
is a valid zip. The method does not close the stream.- Parameters:
stream
- theInputStream
to be validated- Returns:
- true if the
InputStream
is a valid zip, false otherwise
-