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 3e40f9d7c..09714291e 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 @@ -1295,7 +1295,7 @@ public static float readFloat (DataInputStream stream, boolean endian, } public static double readDouble (RandomAccessFile file, boolean endian) - throws IOException + throws IOException { double f = 0.0F; if (endian) { @@ -1354,32 +1354,31 @@ public static double readDouble (DataInputStream stream, boolean endian, return f; } - /* Skip over some bytes. */ - public long skipBytes(DataInputStream stream, long bytesToSkip) - throws IOException + /** Skip over some bytes. Return number of bytes skipped. */ + public long skipBytes(DataInputStream stream, long bytesToSkip) + throws IOException { - return skipBytes (stream, bytesToSkip, null); + return skipBytes(stream, bytesToSkip, null); } - /* Skip over some bytes. */ - public long skipBytes(DataInputStream stream, long bytesToSkip, - ModuleBase counted) - throws IOException + /** Skip over some bytes. Return number of bytes skipped. */ + public long skipBytes(DataInputStream stream, long bytesToSkip, + ModuleBase counted) + throws IOException { - long retVal = 0; - long bytesLeft = bytesToSkip; - while (bytesLeft > 0) { - long n = stream.skip(bytesToSkip); - bytesLeft -= n; - retVal += n; - if (counted != null) { - counted._nByte += n; - } - if (stream.available() == 0) { - break; - } + long totalBytesSkipped = 0; + while (bytesToSkip > 0) { + long bytesSkipped = stream.skip(bytesToSkip); + totalBytesSkipped += bytesSkipped; + bytesToSkip -= bytesSkipped; + // Cease skipping if end of stream reached before + // requested number of bytes have been skipped. + if (stream.available() == 0) break; + } + if (counted != null) { + counted._nByte += totalBytesSkipped; } - return retVal; + return totalBytesSkipped; } /**