commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [jira] [Commented] (COMPRESS-277) IOUtils.skip does not work as advertised
Date Fri, 25 Apr 2014 02:00:18 GMT


BELUGA BEHR commented on COMPRESS-277:

Just my 2 cents on some changes...

Yes.  I helped revamp this code quite a bit, but you get what you pay for :)

InputStream#skip declares:

Skips over and discards n bytes of data from this input stream. The skip method may, for a
variety of reasons, end up skipping over some smaller number of bytes, possibly 0.  This may
result from any of a number of conditions; reaching end of file before n bytes have been skipped
is only one possibility. The actual number of bytes skipped is returned.  If n is negative,
no bytes are skipped.

I would recommend doing away with the call to the local IOUtils and just call skip directly
on the underlying stream.  I'd also amend the JavaDoc to say "end up skipping .. some smaller
number of bytes... reaching the end of the current entry."  The stream is not required to
make any best-effort.  For your example, there should be a BufferedInputStream between the
TarInputStream and the CipherInputStream.  This would put it more in line with all other InputStreams.

You would then have to modify getNextTarEntry() to call the IOUtils#skip method.

> IOUtils.skip does not work as advertised
> ----------------------------------------
>                 Key: COMPRESS-277
>                 URL:
>             Project: Commons Compress
>          Issue Type: Bug
>    Affects Versions: 1.8
>            Reporter: Fabian Lange
>             Fix For: 1.9
> I am trying to feed a TarInputStream from a CipherInputStream.
> It does not work, because IOUtils.skip() does not adhere to the contract it claims in
> "     * <p>This method will only skip less than the requested number of
>      * bytes if the end of the input stream has been reached.</p>"
> However it does:
>             long skipped = input.skip(numToSkip);
>             if (skipped == 0) {
>                 break;
>             }
> And the input stream javadoc says:
> "     * This may result from any of a number of conditions; reaching end of file
>      * before <code>n</code> bytes have been skipped is only one possibility."
> In the case of CipherInputStream, it stops at the end of each byte buffer.
> If you check the IOUtils from colleagues at commons-io, they have considered this case
in IOUtils.skip() where they use a read to skip through the stream.
> An optimized version could combine trying to skip, then read then trying to skip again.

This message was sent by Atlassian JIRA

View raw message