Package org.apache.poi.openxml4j.util
Class ZipInputStreamZipEntrySource
- java.lang.Object
-
- org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ZipEntrySource
public class ZipInputStreamZipEntrySource extends Object implements ZipEntrySource
Provides a way to get at all the ZipEntries from a ZipInputStream, as many times as required. Allows a ZipInputStream to be treated much like a ZipFile, for a price in terms of memory. Be sure to callclose()as soon as you're done, to free up that memory!
-
-
Constructor Summary
Constructors Constructor Description ZipInputStreamZipEntrySource(ZipArchiveThresholdInputStream inp)Reads all the entries from the ZipInputStream into memory, and don't close (since POI 4.0.1) the source stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Indicates we are done with reading, and resources may be freedEnumeration<? extends ZipArchiveEntry>getEntries()Returns an Enumeration of all the EntriesZipArchiveEntrygetEntry(String path)Return an entry by its pathInputStreamgetInputStream(ZipArchiveEntry zipEntry)Returns an InputStream of the decompressed data that makes up the entrystatic intgetThresholdBytesForTempFiles()Get the threshold at which it a zip entry is regarded as too large for holding in memory and the data is put in a temp file instead (defaults to -1 meaning temp files are not used)booleanisClosed()Has close been called already?static voidsetEncryptTempFiles(boolean encrypt)Encrypt temp files when they are used.static voidsetThresholdBytesForTempFiles(int thresholdBytes)Set the threshold at which a zip entry is regarded as too large for holding in memory and the data is put in a temp file insteadstatic booleanshouldEncryptTempFiles()Whether temp files should be encrypted (default false).
-
-
-
Constructor Detail
-
ZipInputStreamZipEntrySource
public ZipInputStreamZipEntrySource(ZipArchiveThresholdInputStream inp) throws IOException
Reads all the entries from the ZipInputStream into memory, and don't close (since POI 4.0.1) the source stream. We'll then eat lots of memory, but be able to work with the entries at-will.- Throws:
IOException- See Also:
setThresholdBytesForTempFiles(int)
-
-
Method Detail
-
setThresholdBytesForTempFiles
public static void setThresholdBytesForTempFiles(int thresholdBytes)
Set the threshold at which a zip entry is regarded as too large for holding in memory and the data is put in a temp file instead- Parameters:
thresholdBytes- number of bytes at which a zip entry is regarded as too large for holding in memory and the data is put in a temp file instead - defaults to -1 meaning temp files are not used and that zip entries with more than 2GB of data after decompressing will fail, 0 means all zip entries are stored in temp files. A threshold like 50000000 (approx 50Mb is recommended)- Since:
- POI 5.1.0
- See Also:
setEncryptTempFiles(boolean)
-
getThresholdBytesForTempFiles
public static int getThresholdBytesForTempFiles()
Get the threshold at which it a zip entry is regarded as too large for holding in memory and the data is put in a temp file instead (defaults to -1 meaning temp files are not used)- Returns:
- threshold in bytes
- Since:
- POI 5.1.0
-
setEncryptTempFiles
public static void setEncryptTempFiles(boolean encrypt)
Encrypt temp files when they are used. Only affects temp files related to zip entries.- Parameters:
encrypt- whether temp files should be encrypted- Since:
- POI 5.1.0
- See Also:
setThresholdBytesForTempFiles(int)
-
shouldEncryptTempFiles
public static boolean shouldEncryptTempFiles()
Whether temp files should be encrypted (default false). Only affects temp files related to zip entries.- Since:
- POI 5.1.0
-
getEntries
public Enumeration<? extends ZipArchiveEntry> getEntries()
Description copied from interface:ZipEntrySourceReturns an Enumeration of all the Entries- Specified by:
getEntriesin interfaceZipEntrySource
-
getInputStream
public InputStream getInputStream(ZipArchiveEntry zipEntry) throws IOException
Description copied from interface:ZipEntrySourceReturns an InputStream of the decompressed data that makes up the entry- Specified by:
getInputStreamin interfaceZipEntrySource- Throws:
IOException
-
close
public void close() throws IOExceptionDescription copied from interface:ZipEntrySourceIndicates we are done with reading, and resources may be freed- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceZipEntrySource- Throws:
IOException
-
isClosed
public boolean isClosed()
Description copied from interface:ZipEntrySourceHas close been called already?- Specified by:
isClosedin interfaceZipEntrySource
-
getEntry
public ZipArchiveEntry getEntry(String path)
Description copied from interface:ZipEntrySourceReturn an entry by its path- Specified by:
getEntryin interfaceZipEntrySource- Parameters:
path- the path in unix-notation- Returns:
- the entry or
nullif not found
-
-