From f695914e89db89e1d76c494ca0928bc9bee172d6 Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Wed, 31 Oct 2018 00:47:51 +0000 Subject: 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 --- src/java/org/apache/poi/util/IOUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/java/org/apache/poi/util') 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" + -- cgit v1.2.3