Skip to content

Commit

Permalink
10.22保存的部分内容
Browse files Browse the repository at this point in the history
Signed-off-by: likaijian <lkjsryx@163.com>
  • Loading branch information
20162430413 committed Oct 22, 2019
1 parent 967cb92 commit 4b319bc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
29 changes: 27 additions & 2 deletions EchoServer/src/main/java/com/plort/polarlights/raincloud/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

/**
* dumplicate: 复制,重写,再做一次
* @author huayu
*
*/
public class Test {

public static void main(String[] args){
Expand All @@ -28,9 +33,9 @@ public static void main(String[] args){
*/
Random r = new Random();
int a2 = r.nextInt();
Character c = '的';
// Character c = '的';
// System.out.println(Integer.toBinaryString((int)c));

System.out.println();
while(buf.isReadable()){
System.out.print((char)buf.readByte());
}
Expand All @@ -45,5 +50,25 @@ public static void main(String[] args){
directBuf.getBytes(directBuf.readerIndex(), a);
System.out.println("readableBytes: "+length+" a.length: "+a.length);
}

ByteBuf sliceBuf = Unpooled.copiedBuffer("I'm a person! How are you?",CharsetUtil.UTF_8);
ByteBuf slicedBuf = sliceBuf.slice(0,13);
System.out.println("slicedBuf :"+slicedBuf.toString(CharsetUtil.UTF_8));
slicedBuf.setByte(0,(byte)'J');
System.out.println("sliceBuf: "+sliceBuf.toString(CharsetUtil.UTF_8));
ByteBuf copiedBuf = sliceBuf.copy(14,sliceBuf.readableBytes());
copiedBuf.setByte(0, (byte)'Y');
System.out.println("copiedBuf: "+copiedBuf.toString(CharsetUtil.UTF_8));
System.out.println("sliceBuf: "+sliceBuf.toString(CharsetUtil.UTF_8));

/**
* 引用计数
*/
assert sliceBuf.refCnt() != 1;
System.out.println("引用计数: "+sliceBuf.refCnt()+";"+slicedBuf.refCnt()+";"+copiedBuf.refCnt());
sliceBuf.release();
System.out.println("引用计数: "+sliceBuf.refCnt()+";"+slicedBuf.refCnt()+";"+copiedBuf.refCnt());


}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<version>4.1.42.Final</version>
</dependency>
</dependencies>

<modules>
<module>EchoServer</module>
<module>EchoClient</module>
</modules>

<build>
<plugins>
<plugin>
Expand Down
Binary file modified 相关资料/Netty实战 电子版.pdf
Binary file not shown.

0 comments on commit 4b319bc

Please sign in to comment.