开发者

Logcat message: Default buffer size used in BufferedInputStream constructor.

开发者 https://www.devze.com 2023-03-05 02:58 出处:网络
While executing my project I am getting the error shown below in logcat: 05-12 12:43:17.268: INFO/global(801): Default buffer size used in BufferedInputStream constructor. It would be better to be e

While executing my project I am getting the error shown below in logcat:

05-12 12:43:17.268: INFO/global(801): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.

My code is shown below. Here the data I passed into commonParser() is long response which I got from the web services.

public void commonParse开发者_如何学Gor(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);
    }
}

The logcat response suggests to me that I use an 8k buffer size but I don't know how to give more size to BufferedInputStream.


You could try changing from InputStreamReader to BufferedReader Because you're already setting the encoding on the InputSource. Then you could set the size of the buffer to 8192 (8k which is what android suggest) So your code could look like ...

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);

...


There is nothing wrong in your code, the message isn't an error. Think of it as an FYI informing you that you can specify the size of the buffer instead of using the default 8k. If lesser size is fine then you can save some memory space that's all

You can choose to ignore the warning if 8KB happens to be exactly what you need, or you can adjust the size with the constructor to tailor it to your needs - as small as possible, as big as necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号