File tree Expand file tree Collapse file tree
main/java/io/netty/buffer
test/java/io/netty/buffer
codec-http/src/main/java/io/netty/handler/codec/http/websocketx
transport-sctp/src/main/java/io/netty/channel/sctp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,8 +90,16 @@ public boolean release(int decrement) {
9090 return data .release (decrement );
9191 }
9292
93+ /**
94+ * Return {@link ByteBuf#toString()} without checking the reference count first. This is useful to implemement
95+ * {@link #toString()}.
96+ */
97+ protected final String contentToString () {
98+ return data .toString ();
99+ }
100+
93101 @ Override
94102 public String toString () {
95- return StringUtil .simpleClassName (this ) + '(' + content (). toString () + ')' ;
103+ return StringUtil .simpleClassName (this ) + '(' + contentToString () + ')' ;
96104 }
97105}
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2015 The Netty Project
3+ *
4+ * The Netty Project licenses this file to you under the Apache License,
5+ * version 2.0 (the "License"); you may not use this file except in compliance
6+ * with the License. You may obtain a copy of the License at:
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ * License for the specific language governing permissions and limitations
14+ * under the License.
15+ */
16+ package io .netty .buffer ;
17+
18+ import org .junit .Test ;
19+
20+ import static org .junit .Assert .*;
21+
22+ public class DefaultByteBufHolderTest {
23+
24+ @ Test
25+ public void testToString () {
26+ ByteBufHolder holder = new DefaultByteBufHolder (Unpooled .buffer ());
27+ assertEquals (1 , holder .refCnt ());
28+ assertNotNull (holder .toString ());
29+ assertTrue (holder .release ());
30+ assertNotNull (holder .toString ());
31+ }
32+ }
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ public int rsv() {
6868
6969 @ Override
7070 public String toString () {
71- return StringUtil .simpleClassName (this ) + "(data: " + content () + ')' ;
71+ return StringUtil .simpleClassName (this ) + "(data: " + contentToString () + ')' ;
7272 }
7373
7474 @ Override
Original file line number Diff line number Diff line change 1717
1818import com .sun .nio .sctp .MessageInfo ;
1919import io .netty .buffer .ByteBuf ;
20- import io .netty .buffer .ByteBufUtil ;
2120import io .netty .buffer .DefaultByteBufHolder ;
2221
2322/**
@@ -191,15 +190,9 @@ public SctpMessage touch(Object hint) {
191190
192191 @ Override
193192 public String toString () {
194- if (refCnt () == 0 ) {
195- return "SctpFrame{" +
196- "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
197- ", unordered=" + unordered +
198- ", data=(FREED)}" ;
199- }
200193 return "SctpFrame{" +
201- "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
202- ", unordered=" + unordered +
203- ", data=" + ByteBufUtil . hexDump ( content () ) + '}' ;
194+ "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
195+ ", unordered=" + unordered +
196+ ", data=" + contentToString ( ) + '}' ;
204197 }
205198}
You can’t perform that action at this time.
0 commit comments