Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recently broken ModuleBase.skipBytes method #194

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions jhove-core/src/main/java/edu/harvard/hul/ois/jhove/ModuleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down