commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Commented: (IO-84) Many classes are limited to length of stream < 2 GB, and behave incorrectly on larger streams
Date Wed, 11 Oct 2006 17:43:38 GMT
    [ http://issues.apache.org/jira/browse/IO-84?page=comments#action_12441512 ] 
            
Niall Pemberton commented on IO-84:
-----------------------------------

I'm happy with throwing the exception.

How about the same behaviour in IOUtils - add 2 new copyLarge() methods and throw an ArithmeticException
in the original copy() methods if they exceed 2GB?

I tried to attach a patch for this but got an error  saying:

"Exception trying to establish attachment directory. Check that the application server and
JIRA have permissions to write to it: com.atlassian.jira.web.util.AttachmentException: Cannot
write to attachment directory. Check that the application server and JIRA have permissions
to write to: /usr/local/tomcat/tomcat-jira/attachments/IO/IO-84"

Something along the following lines though:

    public static int copy(InputStream input, OutputStream output)
            throws IOException {
        long count = copyLarge(input, output);
        if (count > (long)Integer.MAX_VALUE) {
            throw new ArithmeticException("The byte count " + count + " is too large to be
converted to an int");
        }
        return (int)count;
    }

    public static long copyLarge(InputStream input, OutputStream output)
            throws IOException {
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        long count = 0;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }


> Many classes are limited to length of stream < 2 GB, and behave incorrectly on larger
streams
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-84
>                 URL: http://issues.apache.org/jira/browse/IO-84
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 1.2
>         Environment: All
>            Reporter: Evgenii Philippov
>             Fix For: 1.3
>
>         Attachments: io-84-files-larger-than-2gb.patch
>
>
> java int.MAX_VALUE is 2 GB. Classes that handle streams larger than 2 GB will behave
incorrectly.
> For example, see 
> http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java?view=markup
> Method: int copy(InputStream input, OutputStream output).
> The correct method would be: long copy(InputStream input, OutputStream output).
> This issue may affect many classes and routines.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


Mime
View raw message