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

[Bug] Fix skip() api maybe skip unexpected bytes which makes inconsistent data #40

Merged
merged 3 commits into from
Jul 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ public LocalFileReader(String path) throws Exception {

public byte[] read(long offset, int length) {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at -> targetSkip or maxSkip ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

dataInputStream.skip(offset);
long targetSkip = offset;
// comments from skip API:
// The skip method may, for a variety of reasons,
// end up skipping over some smaller number of bytes, possibly 0
// the result should be checked and try again until skip expectation length
while (targetSkip > 0) {
long realSkip = dataInputStream.skip(targetSkip);
if (realSkip == -1) {
throw new RuntimeException("Unexpected EOF when skip bytes");
}
targetSkip -= realSkip;
if (targetSkip > 0) {
LOG.warn("Got unexpected skip for path:" + path + " with offset["
+ offset + "], length[" + length + "], remain[" + targetSkip + "]");
}
}
byte[] buf = new byte[length];
dataInputStream.readFully(buf);
return buf;
Expand Down