View Javadoc
1   /*
2    * Copyright 2012 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    *   https://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 io.netty.util.ByteProcessor;
19  import io.netty.util.internal.ObjectUtil;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.io.OutputStream;
24  import java.nio.ByteBuffer;
25  import java.nio.ByteOrder;
26  import java.nio.channels.FileChannel;
27  import java.nio.channels.GatheringByteChannel;
28  import java.nio.channels.ScatteringByteChannel;
29  import java.nio.charset.Charset;
30  
31  /**
32   * Wrapper which swap the {@link ByteOrder} of a {@link ByteBuf}.
33   *
34   * @deprecated use the Little Endian accessors, e.g. {@code getShortLE}, {@code getIntLE}
35   * instead.
36   */
37  @Deprecated
38  public class SwappedByteBuf extends ByteBuf {
39  
40      private final ByteBuf buf;
41      private final ByteOrder order;
42  
43      public SwappedByteBuf(ByteBuf buf) {
44          this.buf = ObjectUtil.checkNotNull(buf, "buf");
45          if (buf.order() == ByteOrder.BIG_ENDIAN) {
46              order = ByteOrder.LITTLE_ENDIAN;
47          } else {
48              order = ByteOrder.BIG_ENDIAN;
49          }
50      }
51  
52      @Override
53      public ByteOrder order() {
54          return order;
55      }
56  
57      @Override
58      public ByteBuf order(ByteOrder endianness) {
59          if (ObjectUtil.checkNotNull(endianness, "endianness") == order) {
60              return this;
61          }
62          return buf;
63      }
64  
65      @Override
66      public ByteBuf unwrap() {
67          return buf;
68      }
69  
70      @Override
71      public ByteBufAllocator alloc() {
72          return buf.alloc();
73      }
74  
75      @Override
76      public int capacity() {
77          return buf.capacity();
78      }
79  
80      @Override
81      public ByteBuf capacity(int newCapacity) {
82          buf.capacity(newCapacity);
83          return this;
84      }
85  
86      @Override
87      public int maxCapacity() {
88          return buf.maxCapacity();
89      }
90  
91      @Override
92      public boolean isReadOnly() {
93          return buf.isReadOnly();
94      }
95  
96      @Override
97      public ByteBuf asReadOnly() {
98          return Unpooled.unmodifiableBuffer(this);
99      }
100 
101     @Override
102     public boolean isDirect() {
103         return buf.isDirect();
104     }
105 
106     @Override
107     public int readerIndex() {
108         return buf.readerIndex();
109     }
110 
111     @Override
112     public ByteBuf readerIndex(int readerIndex) {
113         buf.readerIndex(readerIndex);
114         return this;
115     }
116 
117     @Override
118     public int writerIndex() {
119         return buf.writerIndex();
120     }
121 
122     @Override
123     public ByteBuf writerIndex(int writerIndex) {
124         buf.writerIndex(writerIndex);
125         return this;
126     }
127 
128     @Override
129     public ByteBuf setIndex(int readerIndex, int writerIndex) {
130         buf.setIndex(readerIndex, writerIndex);
131         return this;
132     }
133 
134     @Override
135     public int readableBytes() {
136         return buf.readableBytes();
137     }
138 
139     @Override
140     public int writableBytes() {
141         return buf.writableBytes();
142     }
143 
144     @Override
145     public int maxWritableBytes() {
146         return buf.maxWritableBytes();
147     }
148 
149     @Override
150     public int maxFastWritableBytes() {
151         return buf.maxFastWritableBytes();
152     }
153 
154     @Override
155     public boolean isReadable() {
156         return buf.isReadable();
157     }
158 
159     @Override
160     public boolean isReadable(int size) {
161         return buf.isReadable(size);
162     }
163 
164     @Override
165     public boolean isWritable() {
166         return buf.isWritable();
167     }
168 
169     @Override
170     public boolean isWritable(int size) {
171         return buf.isWritable(size);
172     }
173 
174     @Override
175     public ByteBuf clear() {
176         buf.clear();
177         return this;
178     }
179 
180     @Override
181     public ByteBuf markReaderIndex() {
182         buf.markReaderIndex();
183         return this;
184     }
185 
186     @Override
187     public ByteBuf resetReaderIndex() {
188         buf.resetReaderIndex();
189         return this;
190     }
191 
192     @Override
193     public ByteBuf markWriterIndex() {
194         buf.markWriterIndex();
195         return this;
196     }
197 
198     @Override
199     public ByteBuf resetWriterIndex() {
200         buf.resetWriterIndex();
201         return this;
202     }
203 
204     @Override
205     public ByteBuf discardReadBytes() {
206         buf.discardReadBytes();
207         return this;
208     }
209 
210     @Override
211     public ByteBuf discardSomeReadBytes() {
212         buf.discardSomeReadBytes();
213         return this;
214     }
215 
216     @Override
217     public ByteBuf ensureWritable(int writableBytes) {
218         buf.ensureWritable(writableBytes);
219         return this;
220     }
221 
222     @Override
223     public int ensureWritable(int minWritableBytes, boolean force) {
224         return buf.ensureWritable(minWritableBytes, force);
225     }
226 
227     @Override
228     public boolean getBoolean(int index) {
229         return buf.getBoolean(index);
230     }
231 
232     @Override
233     public byte getByte(int index) {
234         return buf.getByte(index);
235     }
236 
237     @Override
238     public short getUnsignedByte(int index) {
239         return buf.getUnsignedByte(index);
240     }
241 
242     @Override
243     public short getShort(int index) {
244         return ByteBufUtil.swapShort(buf.getShort(index));
245     }
246 
247     @Override
248     public short getShortLE(int index) {
249         return buf.getShortLE(index);
250     }
251 
252     @Override
253     public int getUnsignedShort(int index) {
254         return getShort(index) & 0xFFFF;
255     }
256 
257     @Override
258     public int getUnsignedShortLE(int index) {
259         return getShortLE(index) & 0xFFFF;
260     }
261 
262     @Override
263     public int getMedium(int index) {
264         return ByteBufUtil.swapMedium(buf.getMedium(index));
265     }
266 
267     @Override
268     public int getMediumLE(int index) {
269         return buf.getMediumLE(index);
270     }
271 
272     @Override
273     public int getUnsignedMedium(int index) {
274         return getMedium(index) & 0xFFFFFF;
275     }
276 
277     @Override
278     public int getUnsignedMediumLE(int index) {
279         return getMediumLE(index) & 0xFFFFFF;
280     }
281 
282     @Override
283     public int getInt(int index) {
284         return ByteBufUtil.swapInt(buf.getInt(index));
285     }
286 
287     @Override
288     public int getIntLE(int index) {
289         return buf.getIntLE(index);
290     }
291 
292     @Override
293     public long getUnsignedInt(int index) {
294         return getInt(index) & 0xFFFFFFFFL;
295     }
296 
297     @Override
298     public long getUnsignedIntLE(int index) {
299         return getIntLE(index) & 0xFFFFFFFFL;
300     }
301 
302     @Override
303     public long getLong(int index) {
304         return ByteBufUtil.swapLong(buf.getLong(index));
305     }
306 
307     @Override
308     public long getLongLE(int index) {
309         return buf.getLongLE(index);
310     }
311 
312     @Override
313     public char getChar(int index) {
314         return (char) getShort(index);
315     }
316 
317     @Override
318     public float getFloat(int index) {
319         return Float.intBitsToFloat(getInt(index));
320     }
321 
322     @Override
323     public double getDouble(int index) {
324         return Double.longBitsToDouble(getLong(index));
325     }
326 
327     @Override
328     public ByteBuf getBytes(int index, ByteBuf dst) {
329         buf.getBytes(index, dst);
330         return this;
331     }
332 
333     @Override
334     public ByteBuf getBytes(int index, ByteBuf dst, int length) {
335         buf.getBytes(index, dst, length);
336         return this;
337     }
338 
339     @Override
340     public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
341         buf.getBytes(index, dst, dstIndex, length);
342         return this;
343     }
344 
345     @Override
346     public ByteBuf getBytes(int index, byte[] dst) {
347         buf.getBytes(index, dst);
348         return this;
349     }
350 
351     @Override
352     public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
353         buf.getBytes(index, dst, dstIndex, length);
354         return this;
355     }
356 
357     @Override
358     public ByteBuf getBytes(int index, ByteBuffer dst) {
359         buf.getBytes(index, dst);
360         return this;
361     }
362 
363     @Override
364     public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
365         buf.getBytes(index, out, length);
366         return this;
367     }
368 
369     @Override
370     public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
371         return buf.getBytes(index, out, length);
372     }
373 
374     @Override
375     public int getBytes(int index, FileChannel out, long position, int length) throws IOException {
376         return buf.getBytes(index, out, position, length);
377     }
378 
379     @Override
380     public CharSequence getCharSequence(int index, int length, Charset charset) {
381         return buf.getCharSequence(index, length, charset);
382     }
383 
384     @Override
385     public ByteBuf setBoolean(int index, boolean value) {
386         buf.setBoolean(index, value);
387         return this;
388     }
389 
390     @Override
391     public ByteBuf setByte(int index, int value) {
392         buf.setByte(index, value);
393         return this;
394     }
395 
396     @Override
397     public ByteBuf setShort(int index, int value) {
398         buf.setShort(index, ByteBufUtil.swapShort((short) value));
399         return this;
400     }
401 
402     @Override
403     public ByteBuf setShortLE(int index, int value) {
404         buf.setShortLE(index, (short) value);
405         return this;
406     }
407 
408     @Override
409     public ByteBuf setMedium(int index, int value) {
410         buf.setMedium(index, ByteBufUtil.swapMedium(value));
411         return this;
412     }
413 
414     @Override
415     public ByteBuf setMediumLE(int index, int value) {
416         buf.setMediumLE(index, value);
417         return this;
418     }
419 
420     @Override
421     public ByteBuf setInt(int index, int value) {
422         buf.setInt(index, ByteBufUtil.swapInt(value));
423         return this;
424     }
425 
426     @Override
427     public ByteBuf setIntLE(int index, int value) {
428         buf.setIntLE(index, value);
429         return this;
430     }
431 
432     @Override
433     public ByteBuf setLong(int index, long value) {
434         buf.setLong(index, ByteBufUtil.swapLong(value));
435         return this;
436     }
437 
438     @Override
439     public ByteBuf setLongLE(int index, long value) {
440         buf.setLongLE(index, value);
441         return this;
442     }
443 
444     @Override
445     public ByteBuf setChar(int index, int value) {
446         setShort(index, value);
447         return this;
448     }
449 
450     @Override
451     public ByteBuf setFloat(int index, float value) {
452         setInt(index, Float.floatToRawIntBits(value));
453         return this;
454     }
455 
456     @Override
457     public ByteBuf setDouble(int index, double value) {
458         setLong(index, Double.doubleToRawLongBits(value));
459         return this;
460     }
461 
462     @Override
463     public ByteBuf setBytes(int index, ByteBuf src) {
464         buf.setBytes(index, src);
465         return this;
466     }
467 
468     @Override
469     public ByteBuf setBytes(int index, ByteBuf src, int length) {
470         buf.setBytes(index, src, length);
471         return this;
472     }
473 
474     @Override
475     public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
476         buf.setBytes(index, src, srcIndex, length);
477         return this;
478     }
479 
480     @Override
481     public ByteBuf setBytes(int index, byte[] src) {
482         buf.setBytes(index, src);
483         return this;
484     }
485 
486     @Override
487     public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
488         buf.setBytes(index, src, srcIndex, length);
489         return this;
490     }
491 
492     @Override
493     public ByteBuf setBytes(int index, ByteBuffer src) {
494         buf.setBytes(index, src);
495         return this;
496     }
497 
498     @Override
499     public int setBytes(int index, InputStream in, int length) throws IOException {
500         return buf.setBytes(index, in, length);
501     }
502 
503     @Override
504     public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
505         return buf.setBytes(index, in, length);
506     }
507 
508     @Override
509     public int setBytes(int index, FileChannel in, long position, int length) throws IOException {
510         return buf.setBytes(index, in, position, length);
511     }
512 
513     @Override
514     public ByteBuf setZero(int index, int length) {
515         buf.setZero(index, length);
516         return this;
517     }
518 
519     @Override
520     public int setCharSequence(int index, CharSequence sequence, Charset charset) {
521         return buf.setCharSequence(index, sequence, charset);
522     }
523 
524     @Override
525     public boolean readBoolean() {
526         return buf.readBoolean();
527     }
528 
529     @Override
530     public byte readByte() {
531         return buf.readByte();
532     }
533 
534     @Override
535     public short readUnsignedByte() {
536         return buf.readUnsignedByte();
537     }
538 
539     @Override
540     public short readShort() {
541         return ByteBufUtil.swapShort(buf.readShort());
542     }
543 
544     @Override
545     public short readShortLE() {
546         return buf.readShortLE();
547     }
548 
549     @Override
550     public int readUnsignedShort() {
551         return readShort() & 0xFFFF;
552     }
553 
554     @Override
555     public int readUnsignedShortLE() {
556         return readShortLE() & 0xFFFF;
557     }
558 
559     @Override
560     public int readMedium() {
561         return ByteBufUtil.swapMedium(buf.readMedium());
562     }
563 
564     @Override
565     public int readMediumLE() {
566         return buf.readMediumLE();
567     }
568 
569     @Override
570     public int readUnsignedMedium() {
571         return readMedium() & 0xFFFFFF;
572     }
573 
574     @Override
575     public int readUnsignedMediumLE() {
576         return readMediumLE() & 0xFFFFFF;
577     }
578 
579     @Override
580     public int readInt() {
581         return ByteBufUtil.swapInt(buf.readInt());
582     }
583 
584     @Override
585     public int readIntLE() {
586         return buf.readIntLE();
587     }
588 
589     @Override
590     public long readUnsignedInt() {
591         return readInt() & 0xFFFFFFFFL;
592     }
593 
594     @Override
595     public long readUnsignedIntLE() {
596         return readIntLE() & 0xFFFFFFFFL;
597     }
598 
599     @Override
600     public long readLong() {
601         return ByteBufUtil.swapLong(buf.readLong());
602     }
603 
604     @Override
605     public long readLongLE() {
606         return buf.readLongLE();
607     }
608 
609     @Override
610     public char readChar() {
611         return (char) readShort();
612     }
613 
614     @Override
615     public float readFloat() {
616         return Float.intBitsToFloat(readInt());
617     }
618 
619     @Override
620     public double readDouble() {
621         return Double.longBitsToDouble(readLong());
622     }
623 
624     @Override
625     public ByteBuf readBytes(int length) {
626         return buf.readBytes(length).order(order());
627     }
628 
629     @Override
630     public ByteBuf readSlice(int length) {
631         return buf.readSlice(length).order(order);
632     }
633 
634     @Override
635     public ByteBuf readRetainedSlice(int length) {
636         return buf.readRetainedSlice(length).order(order);
637     }
638 
639     @Override
640     public ByteBuf readBytes(ByteBuf dst) {
641         buf.readBytes(dst);
642         return this;
643     }
644 
645     @Override
646     public ByteBuf readBytes(ByteBuf dst, int length) {
647         buf.readBytes(dst, length);
648         return this;
649     }
650 
651     @Override
652     public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) {
653         buf.readBytes(dst, dstIndex, length);
654         return this;
655     }
656 
657     @Override
658     public ByteBuf readBytes(byte[] dst) {
659         buf.readBytes(dst);
660         return this;
661     }
662 
663     @Override
664     public ByteBuf readBytes(byte[] dst, int dstIndex, int length) {
665         buf.readBytes(dst, dstIndex, length);
666         return this;
667     }
668 
669     @Override
670     public ByteBuf readBytes(ByteBuffer dst) {
671         buf.readBytes(dst);
672         return this;
673     }
674 
675     @Override
676     public ByteBuf readBytes(OutputStream out, int length) throws IOException {
677         buf.readBytes(out, length);
678         return this;
679     }
680 
681     @Override
682     public int readBytes(GatheringByteChannel out, int length) throws IOException {
683         return buf.readBytes(out, length);
684     }
685 
686     @Override
687     public int readBytes(FileChannel out, long position, int length) throws IOException {
688         return buf.readBytes(out, position, length);
689     }
690 
691     @Override
692     public CharSequence readCharSequence(int length, Charset charset) {
693         return buf.readCharSequence(length, charset);
694     }
695 
696     @Override
697     public String readString(int length, Charset charset) {
698         return buf.readString(length, charset);
699     }
700 
701     @Override
702     public ByteBuf skipBytes(int length) {
703         buf.skipBytes(length);
704         return this;
705     }
706 
707     @Override
708     public ByteBuf writeBoolean(boolean value) {
709         buf.writeBoolean(value);
710         return this;
711     }
712 
713     @Override
714     public ByteBuf writeByte(int value) {
715         buf.writeByte(value);
716         return this;
717     }
718 
719     @Override
720     public ByteBuf writeShort(int value) {
721         buf.writeShort(ByteBufUtil.swapShort((short) value));
722         return this;
723     }
724 
725     @Override
726     public ByteBuf writeShortLE(int value) {
727         buf.writeShortLE((short) value);
728         return this;
729     }
730 
731     @Override
732     public ByteBuf writeMedium(int value) {
733         buf.writeMedium(ByteBufUtil.swapMedium(value));
734         return this;
735     }
736 
737     @Override
738     public ByteBuf writeMediumLE(int value) {
739         buf.writeMediumLE(value);
740         return this;
741     }
742 
743     @Override
744     public ByteBuf writeInt(int value) {
745         buf.writeInt(ByteBufUtil.swapInt(value));
746         return this;
747     }
748 
749     @Override
750     public ByteBuf writeIntLE(int value) {
751         buf.writeIntLE(value);
752         return this;
753     }
754 
755     @Override
756     public ByteBuf writeLong(long value) {
757         buf.writeLong(ByteBufUtil.swapLong(value));
758         return this;
759     }
760 
761     @Override
762     public ByteBuf writeLongLE(long value) {
763         buf.writeLongLE(value);
764         return this;
765     }
766 
767     @Override
768     public ByteBuf writeChar(int value) {
769         writeShort(value);
770         return this;
771     }
772 
773     @Override
774     public ByteBuf writeFloat(float value) {
775         writeInt(Float.floatToRawIntBits(value));
776         return this;
777     }
778 
779     @Override
780     public ByteBuf writeDouble(double value) {
781         writeLong(Double.doubleToRawLongBits(value));
782         return this;
783     }
784 
785     @Override
786     public ByteBuf writeBytes(ByteBuf src) {
787         buf.writeBytes(src);
788         return this;
789     }
790 
791     @Override
792     public ByteBuf writeBytes(ByteBuf src, int length) {
793         buf.writeBytes(src, length);
794         return this;
795     }
796 
797     @Override
798     public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) {
799         buf.writeBytes(src, srcIndex, length);
800         return this;
801     }
802 
803     @Override
804     public ByteBuf writeBytes(byte[] src) {
805         buf.writeBytes(src);
806         return this;
807     }
808 
809     @Override
810     public ByteBuf writeBytes(byte[] src, int srcIndex, int length) {
811         buf.writeBytes(src, srcIndex, length);
812         return this;
813     }
814 
815     @Override
816     public ByteBuf writeBytes(ByteBuffer src) {
817         buf.writeBytes(src);
818         return this;
819     }
820 
821     @Override
822     public int writeBytes(InputStream in, int length) throws IOException {
823         return buf.writeBytes(in, length);
824     }
825 
826     @Override
827     public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
828         return buf.writeBytes(in, length);
829     }
830 
831     @Override
832     public int writeBytes(FileChannel in, long position, int length) throws IOException {
833         return buf.writeBytes(in, position, length);
834     }
835 
836     @Override
837     public ByteBuf writeZero(int length) {
838         buf.writeZero(length);
839         return this;
840     }
841 
842     @Override
843     public int writeCharSequence(CharSequence sequence, Charset charset) {
844         return buf.writeCharSequence(sequence, charset);
845     }
846 
847     @Override
848     public int indexOf(int fromIndex, int toIndex, byte value) {
849         return buf.indexOf(fromIndex, toIndex, value);
850     }
851 
852     @Override
853     public int bytesBefore(byte value) {
854         return buf.bytesBefore(value);
855     }
856 
857     @Override
858     public int bytesBefore(int length, byte value) {
859         return buf.bytesBefore(length, value);
860     }
861 
862     @Override
863     public int bytesBefore(int index, int length, byte value) {
864         return buf.bytesBefore(index, length, value);
865     }
866 
867     @Override
868     public int forEachByte(ByteProcessor processor) {
869         return buf.forEachByte(processor);
870     }
871 
872     @Override
873     public int forEachByte(int index, int length, ByteProcessor processor) {
874         return buf.forEachByte(index, length, processor);
875     }
876 
877     @Override
878     public int forEachByteDesc(ByteProcessor processor) {
879         return buf.forEachByteDesc(processor);
880     }
881 
882     @Override
883     public int forEachByteDesc(int index, int length, ByteProcessor processor) {
884         return buf.forEachByteDesc(index, length, processor);
885     }
886 
887     @Override
888     public ByteBuf copy() {
889         return buf.copy().order(order);
890     }
891 
892     @Override
893     public ByteBuf copy(int index, int length) {
894         return buf.copy(index, length).order(order);
895     }
896 
897     @Override
898     public ByteBuf slice() {
899         return buf.slice().order(order);
900     }
901 
902     @Override
903     public ByteBuf retainedSlice() {
904         return buf.retainedSlice().order(order);
905     }
906 
907     @Override
908     public ByteBuf slice(int index, int length) {
909         return buf.slice(index, length).order(order);
910     }
911 
912     @Override
913     public ByteBuf retainedSlice(int index, int length) {
914         return buf.retainedSlice(index, length).order(order);
915     }
916 
917     @Override
918     public ByteBuf duplicate() {
919         return buf.duplicate().order(order);
920     }
921 
922     @Override
923     public ByteBuf retainedDuplicate() {
924         return buf.retainedDuplicate().order(order);
925     }
926 
927     @Override
928     public int nioBufferCount() {
929         return buf.nioBufferCount();
930     }
931 
932     @Override
933     public ByteBuffer nioBuffer() {
934         return buf.nioBuffer().order(order);
935     }
936 
937     @Override
938     public ByteBuffer nioBuffer(int index, int length) {
939         return buf.nioBuffer(index, length).order(order);
940     }
941 
942     @Override
943     public ByteBuffer internalNioBuffer(int index, int length) {
944         return nioBuffer(index, length);
945     }
946 
947     @Override
948     public ByteBuffer[] nioBuffers() {
949         ByteBuffer[] nioBuffers = buf.nioBuffers();
950         for (int i = 0; i < nioBuffers.length; i++) {
951             nioBuffers[i] = nioBuffers[i].order(order);
952         }
953         return nioBuffers;
954     }
955 
956     @Override
957     public ByteBuffer[] nioBuffers(int index, int length) {
958         ByteBuffer[] nioBuffers = buf.nioBuffers(index, length);
959         for (int i = 0; i < nioBuffers.length; i++) {
960             nioBuffers[i] = nioBuffers[i].order(order);
961         }
962         return nioBuffers;
963     }
964 
965     @Override
966     public boolean hasArray() {
967         return buf.hasArray();
968     }
969 
970     @Override
971     public byte[] array() {
972         return buf.array();
973     }
974 
975     @Override
976     public int arrayOffset() {
977         return buf.arrayOffset();
978     }
979 
980     @Override
981     public boolean hasMemoryAddress() {
982         return buf.hasMemoryAddress();
983     }
984 
985     @Override
986     public boolean isContiguous() {
987         return buf.isContiguous();
988     }
989 
990     @Override
991     public long memoryAddress() {
992         return buf.memoryAddress();
993     }
994 
995     @Override
996     public String toString(Charset charset) {
997         return buf.toString(charset);
998     }
999 
1000     @Override
1001     public String toString(int index, int length, Charset charset) {
1002         return buf.toString(index, length, charset);
1003     }
1004 
1005     @Override
1006     public int refCnt() {
1007         return buf.refCnt();
1008     }
1009 
1010     @Override
1011     final boolean isAccessible() {
1012         return buf.isAccessible();
1013     }
1014 
1015     @Override
1016     public ByteBuf retain() {
1017         buf.retain();
1018         return this;
1019     }
1020 
1021     @Override
1022     public ByteBuf retain(int increment) {
1023         buf.retain(increment);
1024         return this;
1025     }
1026 
1027     @Override
1028     public ByteBuf touch() {
1029         buf.touch();
1030         return this;
1031     }
1032 
1033     @Override
1034     public ByteBuf touch(Object hint) {
1035         buf.touch(hint);
1036         return this;
1037     }
1038 
1039     @Override
1040     public boolean release() {
1041         return buf.release();
1042     }
1043 
1044     @Override
1045     public boolean release(int decrement) {
1046         return buf.release(decrement);
1047     }
1048 
1049     @Override
1050     public int hashCode() {
1051         return buf.hashCode();
1052     }
1053 
1054     @Override
1055     public boolean equals(Object obj) {
1056         if (obj instanceof ByteBuf) {
1057             return ByteBufUtil.equals(this, (ByteBuf) obj);
1058         }
1059         return false;
1060     }
1061 
1062     @Override
1063     public int compareTo(ByteBuf buffer) {
1064         return ByteBufUtil.compare(this, buffer);
1065     }
1066 
1067     @Override
1068     public String toString() {
1069         return "Swapped(" + buf + ')';
1070     }
1071 }