commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "BELUGA BEHR (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (EXEC-92) StreamPumper - Check For EOF
Date Tue, 17 Mar 2015 02:00:43 GMT

    [ https://issues.apache.org/jira/browse/EXEC-92?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14364413#comment-14364413
] 

BELUGA BEHR commented on EXEC-92:
---------------------------------

Here's another example of the "for (0..length)" implementation.  It's an empty array, not
null.

{code:title=OutputStream.java|borderStyle=solid}
public void write(byte b[], int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    } else if ((off < 0) || (off > b.length) || (len < 0) ||
    ((off + len) > b.length) || ((off + len) < 0)) {
       throw new IndexOutOfBoundsException();
    } else if (len == 0) {
        return;
    }
    for (int i = 0 ; i < len ; i++) {
        write(b[off + i]);
    }
}
{code}

> StreamPumper - Check For EOF
> ----------------------------
>
>                 Key: EXEC-92
>                 URL: https://issues.apache.org/jira/browse/EXEC-92
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: BELUGA BEHR
>             Fix For: 1.4
>
>         Attachments: StreamPumper.java.patch
>
>
> When the StreamPumper is copying data from the InputStream to the OutputStream, it would
be safer to check for EOF instead of a read size greater than zero to protect against InputStream
implementations that don't respect the contract as defined in Java core JavaDoc.
> Patch Included.  I took code from the copy method of the IOUtils class.
> {code:title=StreamPumper.java|borderStyle=solid}
> while ((length = is.read(buf)) > 0)
> {
>     os.write(buf, 0, length);
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message