AliSherKashif / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

RFE: add "streaming mode" to implementations for OutputStreams #344

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
While testing MultipartRequest on Android, I realized the net API is allocating 
a buffer the exact size of the Content-Length value as soon as 
impl.openOutputStream() is called, resulting in OutOfMemoryException if file is 
too large.  By implementing "streaming mode" (available since Java 5), I now 
successfully streamed a 1G (yes, gig) file multiple times on a Galaxy Nexus 
without running out of memory.  

I've attached a patch synchronized to the latest code in SVN to enable 
"streaming mode" on the platforms that support it.  The streaming mode is 
enabled when ConnectionRequest is in write mode.  I am unable to test the IOS 
port yet until it's on the server, but I'm hoping this should solve the error 
described in issue 342 comment 6 as well.

(side note, I removed a few @Override annotations in the IOSImplementation 
because they were invalid - ie. no parent method)

Original issue reported on code.google.com by 1815...@coolman.ca on 22 Sep 2012 at 8:14

Attachments:

GoogleCodeExporter commented 9 years ago
I managed to figure out a way to test on IOS, but while debugging I ran across 
something I don't understand - in the IOSImplementation.setOutputStreamingMode, 
I had put a test:

if (connection instanceof HttpURLConnection) {
    // etc
}

When I study the impl code further, this should have evaluated to false and 
been ignored, because impl.connect() returns an 
IOSImplementation.NetworkConnection, which extends InputStream.  BUT, on the 
physical 3G device, the test evaluates to true, connection being an instance of 
an Apache Harmony implementation of HttpURLConnection.  I'm not sure how this 
is happening, unless the IOSImplementation on the server differs from what I'm 
seeing in SVN.

(Further note, the call to connection.setFixedLengthStreamingMode() failed 
because the connection was already open (probably during the call to connect() 
which appears to open as an inputstream immediately) - streaming mode has to be 
enabled before the connection is opened).

Original comment by 1815...@coolman.ca on 22 Sep 2012 at 8:47

GoogleCodeExporter commented 9 years ago
I have no idea why instanceof didn't work for you on iOS. I had some issues 
with it with Array literals but not with plain instanceof. Please ping me about 
this after JavaOne. I'm working hard on the Windows Phone stuff and don't even 
have the sessions for J1 fully ready...

Original comment by shai.almog on 23 Sep 2012 at 7:53

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'll submit a revised patch for this one soon to capture the 
"IllegalStateException" when setting streaming mode, so that it silently 
ignores (except log a warning) if a user tries to set streaming mode after a 
connection is opened.  This will resolve that last note in comment 1. When this 
situation occurs, it only means the user will be limited in the size of data 
they can send.

Original comment by 1815...@coolman.ca on 23 Sep 2012 at 8:44