views:

68

answers:

1

I am getting a timeout with the following code at readUTF. Any idea why?

hc = (HttpConnection) Connector.open("http://twitter.com/statuses/user_timeline/" + username + ".json");
int rc = hc.getResponseCode();

if (rc != HttpConnection.HTTP_OK) {
    throw new IOException("HTTP response code: " + rc);
}

DataInputStream dataInputStream = hc.openDataInputStream();
String list = dataInputStream.readUTF();
+1  A: 

The DataInputStream is only for deserializing Java objects from the stream that were serialized on the other end by Java. I suspect what you really want is instead something like:

InputStream is = hc.openInputStream();
String list = new String(IOUtilities.streamToBytes(is));
Marc Novakowski
Thanks. That's exactly what I needed with slight modification to convert to String.is = hc.openInputStream();String list = new String(IOUtilities.streamToBytes(is));
Hassan Voyeau
ah right - streamToBytes returns a byte[] - I updated the code in my answer to reflect that, thanks
Marc Novakowski