Java: 1.7 OS: Linux (but I don't know which Linux it is)
I have a CharBuffer to contain something I read from socket's BufferedReader. Socket was established that for sure, and when I'm trying to dump it, it gives me an ERROR_FORMAT result.
After that, I read data from socket but caused java.net.SocketException: Connection reset
The Connection reset problem was the problem I'm fixing, but how come CharBuffer.toString() gives an ERROR_FORMAT result ?
Below is my code, is there anything wrong ?
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