Android BufferedReader ReadLine()得到IOException - 预计是一个六角形块大小,如何解决这个问题?

时间:2012-05-08 05:56:16

标签: java android readline bufferedreader ioexception

我在Android中使用BufferedReader接收http流连接,当我收到解析消息时使用代码:

url = new URL(HOST_URL_PUSHMESSAGE);
urlConnection = url.openConnection();
in = (InputStream) urlConnection.getContent();
reader = new BufferedReader(new InputStreamReader(in));
line = reader.readLine();
in.close();

它看起来效果很好,但有时我得到了IOException - 预计是一个六角块大小,但是... 发生在:

line = reader.readLine();

这是怎么发生的?怎么解决这个问题? 更改bufferedreader大小有帮助吗? 感谢

1 个答案:

答案 0 :(得分:1)

查看来源 http://www.java2s.com/Open-Source/Android/android-core/platform-libcore/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedInputStream.java.htm  那里发生异常

try {
    bytesRemainingInChunk = Integer.parseInt(chunkSizeString.trim(), 16);
} catch (NumberFormatException e) {
    throw new IOException("Expected a hex chunk size, but was " + chunkSizeString);
}

在数据中看起来不正确。