1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.buffer;
17
18 import io.netty.util.IllegalReferenceCountException;
19 import io.netty.util.internal.StringUtil;
20
21
22
23
24
25 public class DefaultByteBufHolder implements ByteBufHolder {
26
27 private final ByteBuf data;
28
29 public DefaultByteBufHolder(ByteBuf data) {
30 if (data == null) {
31 throw new NullPointerException("data");
32 }
33 this.data = data;
34 }
35
36 @Override
37 public ByteBuf content() {
38 if (data.refCnt() <= 0) {
39 throw new IllegalReferenceCountException(data.refCnt());
40 }
41 return data;
42 }
43
44 @Override
45 public ByteBufHolder copy() {
46 return new DefaultByteBufHolder(data.copy());
47 }
48
49 @Override
50 public ByteBufHolder duplicate() {
51 return new DefaultByteBufHolder(data.duplicate());
52 }
53
54 @Override
55 public int refCnt() {
56 return data.refCnt();
57 }
58
59 @Override
60 public ByteBufHolder retain() {
61 data.retain();
62 return this;
63 }
64
65 @Override
66 public ByteBufHolder retain(int increment) {
67 data.retain(increment);
68 return this;
69 }
70
71 @Override
72 public boolean release() {
73 return data.release();
74 }
75
76 @Override
77 public boolean release(int decrement) {
78 return data.release(decrement);
79 }
80
81
82
83
84
85 protected final String contentToString() {
86 return data.toString();
87 }
88
89 @Override
90 public String toString() {
91 return StringUtil.simpleClassName(this) + '(' + contentToString() + ')';
92 }
93
94 @Override
95 public boolean equals(Object o) {
96 if (this == o) {
97 return true;
98 }
99 if (o instanceof ByteBufHolder) {
100 return data.equals(((ByteBufHolder) o).content());
101 }
102 return false;
103 }
104
105 @Override
106 public int hashCode() {
107 return data.hashCode();
108 }
109 }