My system is receiving UTF-8 lines ended by 0x0D 0x0A through a SocketChannel. I read data in a ByteBuffer like this:
final ByteBuffer buffer = ByteBuffer.allocate(bufsize);
final int bytesRead = _mySocket.read(buffer);
The buffer is big enough to contain a lot of lines. But I can't have a buffer big enough to contain all lines, lines are processed on the fly.
The buffer can't contain all the lines, so lines may be splitted, a character encoded in more that one byte may also be splitted.
I thought about a solution:
Does java or any library already provide this functionnality ?
Thanks for any answer, Mickaël
我建议使用java.util.Scanner,它知道如何处理SocketChannel,并且知道如何读取行
Scanner sc = new Scanner(_mySocket);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.