[jira] Created: (IO-203) Add skipFully() method for InputStreams

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
Add skipFully() method for InputStreams
---------------------------------------

                 Key: IO-203
                 URL: https://issues.apache.org/jira/browse/IO-203
             Project: Commons IO
          Issue Type: New Feature
          Components: Utilities
            Reporter: Sebb


The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.

It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.

[I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842254#action_12842254 ]

Sebb commented on IO-203:
-------------------------

Started work on this.

I'll implement the following methods:

void skipFully(input, count) - keeps reading and throws EOFException if  end reached before count reached

long skip(input, count) - keeps reading, reports count actually read.

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842280#action_12842280 ]

Sebb commented on IO-203:
-------------------------

Note that Reader.skip(n) and InputStream.skip(n) behave differently according to the Javadoc.

Reader.skip(n) throws IllegalArgumentException for n < 0, whereas InputStread.skip(n) does nothing.


> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated IO-203:
--------------------

    Comment: was deleted

(was: Note that Reader.skip(n) and InputStream.skip(n) behave differently according to the Javadoc.

Reader.skip(n) throws IllegalArgumentException for n < 0, whereas InputStread.skip(n) does nothing.
)

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842483#action_12842483 ]

Sebb commented on IO-203:
-------------------------

Turns out that the basic skip(long) implementations already allow for looping until read() returns -1, so they will skip as much as possible.

So only the skipFully() methods currently make sense, added.

URL: http://svn.apache.org/viewvc?rev=920114&view=rev
Log:
Add skipFully() methods for InputStream and Reader

Modified:
   commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
   commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsTestCase.java

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved IO-203.
---------------------

    Resolution: Fixed

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated IO-203:
--------------------

    Fix Version/s: 2.0

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>             Fix For: 2.0
>
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Reopened: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting reopened IO-203:
------------------------------


I don't think the skipFully() method works as intended the way it's currently implemented. As said in the InputStream.skip() javadocs: "The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0." Thus the skipFully() method should always fall back to read() when the skip() method returns something less than the number of bytes requested.

As an added complexity, note that a FileInputStream allows skipping any number of bytes past the end of the file! If we want to detect that case, the skipFully() method should first skip() n-1 bytes and then try to read() all the remaining bytes.

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>             Fix For: 2.0
>
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842761#action_12842761 ]

Sebb commented on IO-203:
-------------------------

I started out doing that, but as far as I could tell the default implementations of skip call read() repeatedly until EOF anyway - so it would just be repeating the code.

As to FileInputStream, I noticed that when I was trying to set up a test.
I've just confirmed that the behaviour is due to skip() rather than read() - in other words it overrides the default skip() implementation.

So yes, it would after all be useful to have a "proper" skip implementation that cannot be overridden.

How should count < 0 be handled?
At present Reader throws IAE, but InputStream just returns. I'd prefer to see IAE for both.



> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>             Fix For: 2.0
>
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (IO-203) Add skipFully() method for InputStreams

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/IO-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved IO-203.
---------------------

    Resolution: Fixed

Implemented guaranteed skip() methods.

URL: http://svn.apache.org/viewvc?rev=920483&view=rev
Log:
IO-203 - Add skipFully() method for InputStreams
Implement our own skip() methods; rewrite skipFully() to use them

Modified:
   commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
   commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsTestCase.java

> Add skipFully() method for InputStreams
> ---------------------------------------
>
>                 Key: IO-203
>                 URL: https://issues.apache.org/jira/browse/IO-203
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Sebb
>             Fix For: 2.0
>
>
> The skip() method is not guaranteed to skip the requested number of bytes, even if there is more data available. This is particularly true of Buffered input streams.
> It would be useful to have a skip() method that keeps skipping until the required number of bytes have been read, or EOF was reached, in which case it should throw an Exception.
> [I'll add a patch later.]

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.