You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Adrien Grand (JIRA)" <ji...@apache.org> on 2012/09/26 16:03:07 UTC

[jira] [Created] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Adrien Grand created LUCENE-4439:
------------------------------------

             Summary: IOUtils.copy stops copying when InputStream.read returns 0
                 Key: LUCENE-4439
                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
             Project: Lucene - Core
          Issue Type: Bug
    Affects Versions: 4.0
            Reporter: Adrien Grand
            Priority: Minor
             Fix For: 4.1, 5.0


IOUtils.copy has the following lines of code:
{noformat}
      while ((len = fis.read(buffer)) > 0) {
        fos.write(buffer, 0, len);
      }
{noformat}

The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Posted by "Robert Muir (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-4439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13463845#comment-13463845 ] 

Robert Muir commented on LUCENE-4439:
-------------------------------------

Thats just not true
{noformat}
If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b. 
{noformat}

                
> IOUtils.copy stops copying when InputStream.read returns 0
> ----------------------------------------------------------
>
>                 Key: LUCENE-4439
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
>             Project: Lucene - Core
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Adrien Grand
>            Priority: Minor
>             Fix For: 4.1, 5.0
>
>
> IOUtils.copy has the following lines of code:
> {noformat}
>       while ((len = fis.read(buffer)) > 0) {
>         fos.write(buffer, 0, len);
>       }
> {noformat}
> The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Posted by "Uwe Schindler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-4439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13463844#comment-13463844 ] 

Uwe Schindler commented on LUCENE-4439:
---------------------------------------

Good catch!
For sockets it may return 0, too - not for files.
                
> IOUtils.copy stops copying when InputStream.read returns 0
> ----------------------------------------------------------
>
>                 Key: LUCENE-4439
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
>             Project: Lucene - Core
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Adrien Grand
>            Priority: Minor
>             Fix For: 4.1, 5.0
>
>
> IOUtils.copy has the following lines of code:
> {noformat}
>       while ((len = fis.read(buffer)) > 0) {
>         fos.write(buffer, 0, len);
>       }
> {noformat}
> The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Posted by "Uwe Schindler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-4439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13463848#comment-13463848 ] 

Uwe Schindler commented on LUCENE-4439:
---------------------------------------

I agree, see my changed comment! :-)

I would still prefer to check for >=0 instead >0 in this case. But we know here that the buffer is 8 KB (its allocated in the line before).
                
> IOUtils.copy stops copying when InputStream.read returns 0
> ----------------------------------------------------------
>
>                 Key: LUCENE-4439
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
>             Project: Lucene - Core
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Adrien Grand
>            Priority: Minor
>             Fix For: 4.1, 5.0
>
>
> IOUtils.copy has the following lines of code:
> {noformat}
>       while ((len = fis.read(buffer)) > 0) {
>         fos.write(buffer, 0, len);
>       }
> {noformat}
> The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Closed] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Posted by "Adrien Grand (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-4439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Adrien Grand closed LUCENE-4439.
--------------------------------

    Resolution: Invalid
    
> IOUtils.copy stops copying when InputStream.read returns 0
> ----------------------------------------------------------
>
>                 Key: LUCENE-4439
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
>             Project: Lucene - Core
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Adrien Grand
>            Priority: Minor
>             Fix For: 4.1, 5.0
>
>
> IOUtils.copy has the following lines of code:
> {noformat}
>       while ((len = fis.read(buffer)) > 0) {
>         fos.write(buffer, 0, len);
>       }
> {noformat}
> The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Posted by "Robert Muir (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-4439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13463841#comment-13463841 ] 

Robert Muir commented on LUCENE-4439:
-------------------------------------

This can only return 0 if the buffer itself is of size 0
                
> IOUtils.copy stops copying when InputStream.read returns 0
> ----------------------------------------------------------
>
>                 Key: LUCENE-4439
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
>             Project: Lucene - Core
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Adrien Grand
>            Priority: Minor
>             Fix For: 4.1, 5.0
>
>
> IOUtils.copy has the following lines of code:
> {noformat}
>       while ((len = fis.read(buffer)) > 0) {
>         fos.write(buffer, 0, len);
>       }
> {noformat}
> The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Comment Edited] (LUCENE-4439) IOUtils.copy stops copying when InputStream.read returns 0

Posted by "Uwe Schindler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-4439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13463844#comment-13463844 ] 

Uwe Schindler edited comment on LUCENE-4439 at 9/27/12 1:15 AM:
----------------------------------------------------------------

-Good catch!-
-For sockets it may return 0, too - not for files.-

Sorry, no problem at all:
{quote}
If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b.
{quote}
                
      was (Author: thetaphi):
    Good catch!
For sockets it may return 0, too - not for files.
                  
> IOUtils.copy stops copying when InputStream.read returns 0
> ----------------------------------------------------------
>
>                 Key: LUCENE-4439
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4439
>             Project: Lucene - Core
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Adrien Grand
>            Priority: Minor
>             Fix For: 4.1, 5.0
>
>
> IOUtils.copy has the following lines of code:
> {noformat}
>       while ((len = fis.read(buffer)) > 0) {
>         fos.write(buffer, 0, len);
>       }
> {noformat}
> The problem is that the fact that {{InputStream.read}} returns 0 does not mean that it reached the end of the stream (there is -1 for this), so this method might not copy the whole file in rare cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org