Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tballison
Copy link
Contributor

I had to make some local modifications to get the unit tests to work, but those are for another issue.

Let me know if this works, and thank you!

} catch (IOException e) {
throw new IOException(EMPTY_INPUT_STREAM);
int bytesLeft = sasFileProperties.getHeaderLength() - currentFilePosition;
int skipped = sasFileStream.skipBytes(bytesLeft);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a bit risky -- in some rare cases this would skip less bytes than it was asked to, because of network latency for example, so ideally this should be something like skipFully in IOUtils. As we don't really want to bring another dependency, probably it makes sense to copy IOUtils' logic (without some IFs, etc, of course). Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, just seeing this now. Yes, I completely agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like DataInputStream's skipBytes does do the while...loop so that's not a problem...I don't think.

What is a problem is that FileInputStream can lie about bytes skipped, so y, I'll copy and paste from IOUtils.skipFully().

Copy link
Contributor Author

@tballison tballison Jun 19, 2020

Choose a reason for hiding this comment

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

From the decompiler in Java 8 on DataInputStream

    public final int skipBytes(int n) throws IOException {
        int total = 0;
        int cur = 0;

        while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
            total += cur;
        }

        return total;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I don't like about the current version is that if readFully fails, then eof=true and the user will get a null on next row instead of an EOFException, but if skip fails, then there's an exception.

Any preference/recommendation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agree, so I see the reason in your suggested change, so I would avoid readFully in favor of IOUtils.skipFully (it's just better than streams' skip/read methods) so perhaps just copy and paste those IOUtils methods as the licence is the same?

@printsev
Copy link
Contributor

Improved this behaviour as a part of #82

@printsev printsev closed this Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants