Package org.goplanit.utils.zip
Class ZipUtils
- java.lang.Object
-
- org.goplanit.utils.zip.ZipUtils
-
public class ZipUtils extends Object
Utilities for accessing content in zip files- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description ZipUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PlanitZipInputStream
createZipEntryInputStream(URL zipFileLocation, String zipEntryFileName, boolean logInfo)
Collect the input stream for a given zip file entry.static PlanitZipFileInputStream
createZipEntryInputStream(ZipFile zipFile, String zipEntryFileName)
Collect the input stream for a given zip file entry.static ZipFile
createZipFile(URL zipUrl)
Create a zip file from a URLstatic PlanitZipInputStream
createZipInputStream(URL zipFileLocation)
Collect the zip input stream for a given zip file (starting point).static boolean
positionZipEntryInputStream(ZipInputStream zipInputStream, String zipEntryFileName)
Move the passed in zip input stream to the starting point of the given zip file entry.
-
-
-
Method Detail
-
createZipInputStream
public static PlanitZipInputStream createZipInputStream(URL zipFileLocation) throws FileNotFoundException, URISyntaxException
Collect the zip input stream for a given zip file (starting point). Note that invoked needs to close the input stream when done!- Parameters:
zipFileLocation
- to use- Returns:
- input stream created
- Throws:
URISyntaxException
- thrown if errorFileNotFoundException
- thrown if error
-
createZipFile
public static ZipFile createZipFile(URL zipUrl) throws ZipException, IOException
Create a zip file from a URL- Parameters:
zipUrl
- to create zip file for- Returns:
- created zip file
- Throws:
ZipException
- thrown if errorIOException
- thrown if error
-
createZipEntryInputStream
public static PlanitZipInputStream createZipEntryInputStream(URL zipFileLocation, String zipEntryFileName, boolean logInfo) throws URISyntaxException, IOException
Collect the input stream for a given zip file entry. The returned wrapper stream should be positioned at the beginning of the internal file Note that invoked needs to close the input stream when done! This approach uses a ZipInputStream rather than a ZipFile for performance reasons as it appears to be around 5 times faster for a regular sized zip file- Parameters:
zipFileLocation
- of the zip filezipEntryFileName
- of the file within the ziplogInfo
- when true log extensive information on entries in zip file, file size and whether the file exists for debugging purposes- Returns:
- input stream created, if file not found by iterating over entries null is returned
- Throws:
URISyntaxException
- thrown if errorIOException
- thrown if input stream cannot be closed when necessary
-
createZipEntryInputStream
public static PlanitZipFileInputStream createZipEntryInputStream(ZipFile zipFile, String zipEntryFileName) throws URISyntaxException, IOException
Collect the input stream for a given zip file entry. The returned wrapper stream is positioned at the beginning of the internal file- Parameters:
zipFile
- to usezipEntryFileName
- of the file within the zip- Returns:
- input stream created, if file not found by iterating over entries null is returned
- Throws:
URISyntaxException
- thrown if errorIOException
- thrown if input stream cannot be closed when necessary
-
positionZipEntryInputStream
public static boolean positionZipEntryInputStream(ZipInputStream zipInputStream, String zipEntryFileName)
Move the passed in zip input stream to the starting point of the given zip file entry.- Parameters:
zipInputStream
- to usezipEntryFileName
- of the file within the zip- Returns:
- true when successfully positioned the input stream, false otherwise
-
-