【问题标题】:Android BufferedReader ReadLine() got IOException - Expected a hex chunk size , How to fix this?Android BufferedReader ReadLine() got IOException - Expected a hex chunk size ,如何解决这个问题?
【发布时间】:2012-05-16 14:57:08
【问题描述】:

我在 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();

这是如何发生的?如何解决? 更改缓冲阅读器大小有帮助吗? 谢谢

【问题讨论】:

    标签: java android readline bufferedreader ioexception


    【解决方案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);
    }
    

    数据中的某些内容似乎不正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      相关资源
      最近更新 更多