publicstaticvoidmain(String[] args){ByteBuffer byteBuffer1 =ByteBuffer.allocate(60);byteBuffer1.put("Hello World\nWhat is you name?\nI am Licky!\nHo".getBytes());splice(byteBuffer1);byteBuffer1.put("w old are you\nI am ten ".getBytes());splice(byteBuffer1);byteBuffer1.put("year`s old!\n".getBytes());splice(byteBuffer1);}publicstaticvoidsplice(ByteBuffer byteBuffer){byteBuffer.flip();//开启读取模式ByteBufferUtil.debugAll("byteBuffer.flip()", byteBuffer);for(int i =0; i < byteBuffer.limit(); i++){if(byteBuffer.get(i)=='\n'){int size = i +1- byteBuffer.position();ByteBuffer newByteBuffer =ByteBuffer.allocate(size);for(int i1 =0; i1 < size; i1++){newByteBuffer.put(byteBuffer.get());}ByteBufferUtil.debugAll("println", byteBuffer);System.out.println("拆包输出:"+newString(newByteBuffer.array()));}}byteBuffer.compact();ByteBufferUtil.debugAll("compact()", byteBuffer);}
输出结果
源码分析1
1.输出完整字符串 Hello World\nWhat is you name?\nI am Licky!\nHo
epoll也是一种linux中的多路转接方案(epoll也是只负责IO过程中的"等")
一、epoll相关接口的使用
1.epoll_create
int epoll_create(int size);
功能:创建一个epoll模型 ① int size:没意义了 >0就行
返回值:返回一个文件…