diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2018-04-27 21:38:19 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2018-04-27 21:38:19 +0000 |
commit | f94245e9d876c49462bc66bdc573ea11160b617a (patch) | |
tree | b3ad7edff8643e1fdb024a568f1e071f98232537 /src/examples | |
parent | 48f03cd45abcef0ca26e91e2080f430557a2c70b (diff) | |
download | poi-f94245e9d876c49462bc66bdc573ea11160b617a.tar.gz poi-f94245e9d876c49462bc66bdc573ea11160b617a.zip |
#59893 - Forbid calls to InputStream.available
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1830400 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptor.java | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptor.java b/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptor.java index d3c837a44d..e93c23b79a 100644 --- a/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptor.java +++ b/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptor.java @@ -17,15 +17,17 @@ package org.apache.poi.poifs.poibrowser; -import java.io.*; -import org.apache.poi.poifs.filesystem.*; +import java.io.IOException; + +import org.apache.poi.poifs.filesystem.DocumentInputStream; +import org.apache.poi.poifs.filesystem.POIFSDocumentPath; import org.apache.poi.util.IOUtils; /** * <p>Describes the most important (whatever that is) features of a * {@link POIFSDocumentPath}.</p> */ -public class DocumentDescriptor +class DocumentDescriptor { //arbitrarily selected; may need to increase @@ -54,26 +56,20 @@ public class DocumentDescriptor public DocumentDescriptor(final String name, final POIFSDocumentPath path, final DocumentInputStream stream, - final int nrOfBytes) - { + final int nrOfBytes) { this.name = name; this.path = path; this.stream = stream; - try - { - size = stream.available(); - if (stream.markSupported()) - { + try { + if (stream.markSupported()) { stream.mark(nrOfBytes); - final byte[] b = IOUtils.safelyAllocate(nrOfBytes, MAX_RECORD_LENGTH); - final int read = stream.read(b, 0, Math.min(size, b.length)); - bytes = new byte[read]; - System.arraycopy(b, 0, bytes, 0, read); + bytes = IOUtils.toByteArray(stream, nrOfBytes, MAX_RECORD_LENGTH); stream.reset(); + } else { + bytes = new byte[0]; } - } - catch (IOException ex) - { + size = bytes.length + stream.available(); + } catch (IOException ex) { System.out.println(ex); } } |