From 7a1fb4894f9a59b8840e1a82ae268bea7c3cb0c8 Mon Sep 17 00:00:00 2001 From: RogerMathisen Date: Fri, 9 Sep 2016 14:44:40 +0200 Subject: [PATCH] -Modified skipBytes() to handle skipping past the end of the file. Issue #71. --- .../edu/harvard/hul/ois/jhove/ModuleBase.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/ModuleBase.java b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/ModuleBase.java index 470bd0ed3..6ddcd2614 100644 --- a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/ModuleBase.java +++ b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/ModuleBase.java @@ -1362,15 +1362,20 @@ public long skipBytes(DataInputStream stream, long bytesToSkip) } /* Skip over some bytes. */ - public long skipBytes(DataInputStream stream, long bytesToSkip, - ModuleBase counted) - throws IOException - { - long n = stream.skip(bytesToSkip); - if (counted != null) { - counted._nByte += n; + public long skipBytes(DataInputStream stream, long bytesToSkip, ModuleBase counted) throws IOException { + long retVal = 0; + while (bytesToSkip > 0) { + long n = stream.skip(bytesToSkip); // skip() don't throw an exception if we skip past the end of the file. + bytesToSkip -= n; + retVal += n; + if (counted != null) { + counted._nByte += n; + } + if (stream.available() == 0) { // Need this in case we are past the end of the file. + break; + } } - return n; + return retVal; } /**