incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Grieve (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-1413) FileTransfer causes an exception when trying to handle the response
Date Thu, 13 Sep 2012 12:45:07 GMT

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

Andrew Grieve commented on CB-1413:
-----------------------------------

Copy and paste this code into your FileTransfer.jave:

    /**
     * This input stream won't read() after the underlying stream is exhausted.
     * http://code.google.com/p/android/issues/detail?id=14562
     */
    private static final class DoneHandlerInputStream extends FilterInputStream {
        private boolean done;

        public DoneHandlerInputStream(InputStream stream) {
            super(stream);
        }

        @Override public int read(byte[] bytes, int offset, int count) throws IOException
{
            if (!done) {
                int result = super.read(bytes, offset, count);
                if (result != -1) {
                    return result;
                }
            }
            done = true;
            return -1;
        }
    }


Then, whenever you see "foo.getInputStream()" in FileTransfer.jave, replace it with "new DoneHandlerInputStream(foo.getInputStream())"

If you want to try this out, it would be great to have you verify whether this fixes the bug
for you or not.
                
> FileTransfer causes an exception when trying to handle the response
> -------------------------------------------------------------------
>
>                 Key: CB-1413
>                 URL: https://issues.apache.org/jira/browse/CB-1413
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.0.0
>         Environment: Android SDK: 2.3.3
>            Reporter: Tom Drummond
>            Assignee: Andrew Grieve
>             Fix For: 2.2.0
>
>
> I'm getting a BufferedInputStream error when trying to upload an image with Android.
> *Sample Code*
> {code:javascript}
> var options = new FileUploadOptions();
> options.fileKey = "image";
> options.chunkedMode = false;
> var ft = new FileTransfer();
> ft.upload(imageURI, "https://192.168.1.128:5000/", function(resp) {
>     console.log(JSON.stringify(resp));
> , function(e) {
>     console.log(JSON.stringify(e));
> }, options);
> {code}
> *JS Result*
> {code:javascript}
> {"target":"http://192.168.1.128:5000/","source":"file:///mnt/sdcard/Android/data/app/cache/1346773635225.jpg","http_status":200,"code":3}
> {code}
> *Exception*
> {code:java}
> java.io.IOException: BufferedInputStream is closed
>  	at java.io.BufferedInputStream.streamClosed(BufferedInputStream.java:116)
>  	at java.io.BufferedInputStream.read(BufferedInputStream.java:274)
>  	at org.apache.harmony.luni.internal.net.www.protocol.http.UnknownLengthHttpInputStream.read(UnknownLengthHttpInputStream.java:40)
>  	at org.apache.harmony.luni.internal.net.www.protocol.http.AbstractHttpInputStream.read(AbstractHttpInputStream.java:56)
>  	at java.io.DataInputStream.readLine(DataInputStream.java:310)
>  	at org.apache.cordova.FileTransfer.upload(FileTransfer.java:286)
>  	at org.apache.cordova.FileTransfer.execute(FileTransfer.java:85)
>  	at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:192)
>  	at java.lang.Thread.run(Thread.java:1019)
> {code}
> After some Googling it appears to be an issue in Android 2.3.x (I was testing on 2.3.3).
I can confirm that it's not a problem in Android 4.1 (at least in the simulator).
> Related links:
> - http://stackoverflow.com/questions/4841925/java-io-ioexception-bufferedinputstream-is-closed-in-android-2-3
> - http://code.google.com/p/android/issues/detail?id=14562

--
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

Mime
View raw message