Java:1.7操作系统:Linux(但我不知道它是哪个Linux)
我有一个 CharBuffer 来包含我从套接字的 BufferedReader 读取的内容。Socket 是肯定建立的,当我试图转储它时,它给了我一个ERROR_FORMAT结果。
之后,我从套接字读取数据但导致java.net.SocketException: Connection reset
连接重置问题是我要解决的问题,但是 CharBuffer.toString() 怎么会给出ERROR_FORMAT结果?
下面是我的代码,有什么问题吗?
Socket connectionSocket=xxxxxx; //Connected socket given by other library
connectionSocket.setSoTimeout(75*1000);
CharBuffer charBuffer=CharBuffer.allocate(1024);
BufferedReader bufferedReader=null;
bufferedReader=new BufferedReader(new InputStreamReader(connectionSocket.getInputStream(), "BIG5"));
while((bufferedReader.read(charBuffer))!=-1) // in 2nd time, this line throw a java.net.SocketException: Connection reset
{
charBuffer.flip();
respStr.append(charBuffer);
log.info("CharBuffer: "+charBuffer.toString()); // this line runs just 1 tine, print result: "CharBuffer: 2016102618353211301 : ERROR_FORMAT"
charBuffer.clear();
}
log.info("CharBuffer all: "+charBuffer.toString()); // dodn't been execute