J2ME, process a never-ending http connection line by line
I have to write a simple http connection reader in J2ME who has to process a chunked connection line by line.
I tried this:
connection = (HttpConnection) Connector.open( url );
inputStream = connection.openDataInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c ;
while (true) {
开发者_开发百科 c = inputStream.read();
if (c == -1)
break;
if (c == 10) { // new line \n
handler( baos.toString() );
baos = new ByteArrayOutputStream();
}
else
baos.write(c);
}
but it seems to start the entire process only when the server close the connection.
How do i have to manage new incoming lines without have to buffer everything ?
Thank you!
It seems to be impossible using HttpConnection, but it works with StreamConnection
精彩评论