Java Logcat消息:BufferedInputStream构造函数中使用的默认缓冲区大小。

Java Logcat消息:BufferedInputStream构造函数中使用的默认缓冲区大小。,java,android,bufferedinputstream,Java,Android,Bufferedinputstream,在执行我的项目时,我在logcat中遇到如下错误: 05-12 12:43:17.268:INFO/global(801):BufferedInputStream构造函数中使用的默认缓冲区大小。如果需要8k缓冲区,最好是显式的 我的代码如下所示。这里,我传递到commonParser()的数据是我从web服务获得的长响应 public void commonParser(String data) { try { if(data!=null) {

在执行我的项目时,我在logcat中遇到如下错误:

05-12 12:43:17.268:INFO/global(801):BufferedInputStream构造函数中使用的默认缓冲区大小。如果需要8k缓冲区,最好是显式的

我的代码如下所示。这里,我传递到
commonParser()
的数据是我从web服务获得的长响应

public void commonParser(String data)
{
    try
    {
        if(data!=null)
        {
            InputStream is = new ByteArrayInputStream(data.getBytes());
            Reader reader = new InputStreamReader(is, "UTF-8");
            InputSource inputSource = new InputSource(reader);
            inputSource.setEncoding("UTF-8");
            SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
            sp.parse(inputSource, this);
        }
    } catch (UnsupportedEncodingException e) {
        System.out.println("Common Parser Unsupported Encoding :: "+e);
    } catch (ParserConfigurationException e) {
        System.out.println("Parse Config error"+e);
    } catch (SAXException e) {
        System.out.println("Sax error "+e);
    } catch (IOException e) {
        System.out.println("IO Error "+e);
    }
}

logcat响应向我建议使用8k缓冲区大小,但我不知道如何为
BufferedInputStream

提供更多大小。您可以尝试从InputStreamReader更改为BufferedReader 因为您已经在InputSource上设置了编码。 然后您可以将缓冲区的大小设置为8192(android建议使用8k) 所以你的代码看起来像


代码中没有错误,消息不是错误。可以将其视为一个供参考的信息,告知您可以指定缓冲区的大小,而不是使用默认的8k。如果较小的大小是好的,那么您可以节省一些内存空间,仅此而已


如果8KB恰好是您所需要的,您可以选择忽略警告,或者您可以使用构造函数调整大小以使其适合您的需要-尽可能小,尽可能大

答案在[帖][1][1]中:
InputStream is = new ByteArrayInputStream(data.getBytes());
// use BufferedInputStream instead of InputStreamReader
BufferedInputStream bis = new BufferedInputStream(is, 8192);
InputSource inputSource = new InputSource(bis);
inputSource.setEncoding("UTF-8");
SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
sp.parse(inputSource, this);

...