FakeZipEntry: pre-allocate ByteArrayOutputStream when zip entry size is known to prevent reallocation
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1124179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2cf314de68
commit
209a45ee66
@ -108,7 +108,20 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource {
|
|||||||
super(entry.getName());
|
super(entry.getName());
|
||||||
|
|
||||||
// Grab the de-compressed contents for later
|
// Grab the de-compressed contents for later
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos;
|
||||||
|
|
||||||
|
long entrySize = entry.getSize();
|
||||||
|
|
||||||
|
if (entrySize !=-1) {
|
||||||
|
if (entrySize>=Integer.MAX_VALUE) {
|
||||||
|
throw new IOException("ZIP entry size is too large");
|
||||||
|
}
|
||||||
|
|
||||||
|
baos = new ByteArrayOutputStream((int) entrySize);
|
||||||
|
} else {
|
||||||
|
baos = new ByteArrayOutputStream();
|
||||||
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
int read = 0;
|
int read = 0;
|
||||||
while( (read = inp.read(buffer)) != -1 ) {
|
while( (read = inp.read(buffer)) != -1 ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user