diff options
author | Tim Allison <tallison@apache.org> | 2018-10-31 00:47:51 +0000 |
---|---|---|
committer | Tim Allison <tallison@apache.org> | 2018-10-31 00:47:51 +0000 |
commit | f695914e89db89e1d76c494ca0928bc9bee172d6 (patch) | |
tree | 91d773df29520d5c46cc3116d682a0554461aabe /src/java/org/apache/poi/util | |
parent | c956084b0d7c807f21c93f4a82571496d4bb65b1 (diff) | |
download | poi-f695914e89db89e1d76c494ca0928bc9bee172d6.tar.gz poi-f695914e89db89e1d76c494ca0928bc9bee172d6.zip |
bug 62624 -- fix loop identified as dodgy by FindBugs; add a other sanity checks.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845299 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/util')
-rw-r--r-- | src/java/org/apache/poi/util/IOUtils.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/util/IOUtils.java b/src/java/org/apache/poi/util/IOUtils.java index 839663cda3..009510ffc6 100644 --- a/src/java/org/apache/poi/util/IOUtils.java +++ b/src/java/org/apache/poi/util/IOUtils.java @@ -548,6 +548,22 @@ public final class IOUtils { return new byte[(int)length]; } + /** + * Simple utility function to check that you haven't hit EOF + * when reading a byte. + * + * @param is inputstream to read + * @return byte read, unless + * @throws IOException on IOException or EOF if -1 is read + */ + public static int readByte(InputStream is) throws IOException { + int b = is.read(); + if (b == -1) { + throw new EOFException(); + } + return b; + } + private static void throwRFE(long length, int maxLength) { throw new RecordFormatException("Tried to allocate an array of length "+length + ", but "+ maxLength+" is the maximum for this record type.\n" + |