View Javadoc
1   /*
2    * Copyright 2013 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  
17  package io.netty.buffer;
18  
19  import io.netty.util.internal.StringUtil;
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.GatheringByteChannel;
27  import java.nio.channels.ScatteringByteChannel;
28  import java.nio.charset.Charset;
29  
30  public class WrappedByteBuf extends ByteBuf {
31  
32      protected final ByteBuf buf;
33  
34      protected WrappedByteBuf(ByteBuf buf) {
35          if (buf == null) {
36              throw new NullPointerException("buf");
37          }
38          this.buf = buf;
39      }
40  
41      @Override
42      public boolean hasMemoryAddress() {
43          return buf.hasMemoryAddress();
44      }
45  
46      @Override
47      public long memoryAddress() {
48          return buf.memoryAddress();
49      }
50  
51      @Override
52      public int capacity() {
53          return buf.capacity();
54      }
55  
56      @Override
57      public ByteBuf capacity(int newCapacity) {
58          buf.capacity(newCapacity);
59          return this;
60      }
61  
62      @Override
63      public int maxCapacity() {
64          return buf.maxCapacity();
65      }
66  
67      @Override
68      public ByteBufAllocator alloc() {
69          return buf.alloc();
70      }
71  
72      @Override
73      public ByteOrder order() {
74          return buf.order();
75      }
76  
77      @Override
78      public ByteBuf order(ByteOrder endianness) {
79          return buf.order(endianness);
80      }
81  
82      @Override
83      public ByteBuf unwrap() {
84          return buf;
85      }
86  
87      @Override
88      public boolean isDirect() {
89          return buf.isDirect();
90      }
91  
92      @Override
93      public int readerIndex() {
94          return buf.readerIndex();
95      }
96  
97      @Override
98      public ByteBuf readerIndex(int readerIndex) {
99          buf.readerIndex(readerIndex);
100         return this;
101     }
102 
103     @Override
104     public int writerIndex() {
105         return buf.writerIndex();
106     }
107 
108     @Override
109     public ByteBuf writerIndex(int writerIndex) {
110         buf.writerIndex(writerIndex);
111         return this;
112     }
113 
114     @Override
115     public ByteBuf setIndex(int readerIndex, int writerIndex) {
116         buf.setIndex(readerIndex, writerIndex);
117         return this;
118     }
119 
120     @Override
121     public int readableBytes() {
122         return buf.readableBytes();
123     }
124 
125     @Override
126     public int writableBytes() {
127         return buf.writableBytes();
128     }
129 
130     @Override
131     public int maxWritableBytes() {
132         return buf.maxWritableBytes();
133     }
134 
135     @Override
136     public boolean isReadable() {
137         return buf.isReadable();
138     }
139 
140     @Override
141     public boolean isWritable() {
142         return buf.isWritable();
143     }
144 
145     @Override
146     public ByteBuf clear() {
147         buf.clear();
148         return this;
149     }
150 
151     @Override
152     public ByteBuf markReaderIndex() {
153         buf.markReaderIndex();
154         return this;
155     }
156 
157     @Override
158     public ByteBuf resetReaderIndex() {
159         buf.resetReaderIndex();
160         return this;
161     }
162 
163     @Override
164     public ByteBuf markWriterIndex() {
165         buf.markWriterIndex();
166         return this;
167     }
168 
169     @Override
170     public ByteBuf resetWriterIndex() {
171         buf.resetWriterIndex();
172         return this;
173     }
174 
175     @Override
176     public ByteBuf discardReadBytes() {
177         buf.discardReadBytes();
178         return this;
179     }
180 
181     @Override
182     public ByteBuf discardSomeReadBytes() {
183         buf.discardSomeReadBytes();
184         return this;
185     }
186 
187     @Override
188     public ByteBuf ensureWritable(int minWritableBytes) {
189         buf.ensureWritable(minWritableBytes);
190         return this;
191     }
192 
193     @Override
194     public int ensureWritable(int minWritableBytes, boolean force) {
195         return buf.ensureWritable(minWritableBytes, force);
196     }
197 
198     @Override
199     public boolean getBoolean(int index) {
200         return buf.getBoolean(index);
201     }
202 
203     @Override
204     public byte getByte(int index) {
205         return buf.getByte(index);
206     }
207 
208     @Override
209     public short getUnsignedByte(int index) {
210         return buf.getUnsignedByte(index);
211     }
212 
213     @Override
214     public short getShort(int index) {
215         return buf.getShort(index);
216     }
217 
218     @Override
219     public int getUnsignedShort(int index) {
220         return buf.getUnsignedShort(index);
221     }
222 
223     @Override
224     public int getMedium(int index) {
225         return buf.getMedium(index);
226     }
227 
228     @Override
229     public int getUnsignedMedium(int index) {
230         return buf.getUnsignedMedium(index);
231     }
232 
233     @Override
234     public int getInt(int index) {
235         return buf.getInt(index);
236     }
237 
238     @Override
239     public long getUnsignedInt(int index) {
240         return buf.getUnsignedInt(index);
241     }
242 
243     @Override
244     public long getLong(int index) {
245         return buf.getLong(index);
246     }
247 
248     @Override
249     public char getChar(int index) {
250         return buf.getChar(index);
251     }
252 
253     @Override
254     public float getFloat(int index) {
255         return buf.getFloat(index);
256     }
257 
258     @Override
259     public double getDouble(int index) {
260         return buf.getDouble(index);
261     }
262 
263     @Override
264     public ByteBuf getBytes(int index, ByteBuf dst) {
265         buf.getBytes(index, dst);
266         return this;
267     }
268 
269     @Override
270     public ByteBuf getBytes(int index, ByteBuf dst, int length) {
271         buf.getBytes(index, dst, length);
272         return this;
273     }
274 
275     @Override
276     public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
277         buf.getBytes(index, dst, dstIndex, length);
278         return this;
279     }
280 
281     @Override
282     public ByteBuf getBytes(int index, byte[] dst) {
283         buf.getBytes(index, dst);
284         return this;
285     }
286 
287     @Override
288     public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
289         buf.getBytes(index, dst, dstIndex, length);
290         return this;
291     }
292 
293     @Override
294     public ByteBuf getBytes(int index, ByteBuffer dst) {
295         buf.getBytes(index, dst);
296         return this;
297     }
298 
299     @Override
300     public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
301         buf.getBytes(index, out, length);
302         return this;
303     }
304 
305     @Override
306     public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
307         return buf.getBytes(index, out, length);
308     }
309 
310     @Override
311     public ByteBuf setBoolean(int index, boolean value) {
312         buf.setBoolean(index, value);
313         return this;
314     }
315 
316     @Override
317     public ByteBuf setByte(int index, int value) {
318         buf.setByte(index, value);
319         return this;
320     }
321 
322     @Override
323     public ByteBuf setShort(int index, int value) {
324         buf.setShort(index, value);
325         return this;
326     }
327 
328     @Override
329     public ByteBuf setMedium(int index, int value) {
330         buf.setMedium(index, value);
331         return this;
332     }
333 
334     @Override
335     public ByteBuf setInt(int index, int value) {
336         buf.setInt(index, value);
337         return this;
338     }
339 
340     @Override
341     public ByteBuf setLong(int index, long value) {
342         buf.setLong(index, value);
343         return this;
344     }
345 
346     @Override
347     public ByteBuf setChar(int index, int value) {
348         buf.setChar(index, value);
349         return this;
350     }
351 
352     @Override
353     public ByteBuf setFloat(int index, float value) {
354         buf.setFloat(index, value);
355         return this;
356     }
357 
358     @Override
359     public ByteBuf setDouble(int index, double value) {
360         buf.setDouble(index, value);
361         return this;
362     }
363 
364     @Override
365     public ByteBuf setBytes(int index, ByteBuf src) {
366         buf.setBytes(index, src);
367         return this;
368     }
369 
370     @Override
371     public ByteBuf setBytes(int index, ByteBuf src, int length) {
372         buf.setBytes(index, src, length);
373         return this;
374     }
375 
376     @Override
377     public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
378         buf.setBytes(index, src, srcIndex, length);
379         return this;
380     }
381 
382     @Override
383     public ByteBuf setBytes(int index, byte[] src) {
384         buf.setBytes(index, src);
385         return this;
386     }
387 
388     @Override
389     public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
390         buf.setBytes(index, src, srcIndex, length);
391         return this;
392     }
393 
394     @Override
395     public ByteBuf setBytes(int index, ByteBuffer src) {
396         buf.setBytes(index, src);
397         return this;
398     }
399 
400     @Override
401     public int setBytes(int index, InputStream in, int length) throws IOException {
402         return buf.setBytes(index, in, length);
403     }
404 
405     @Override
406     public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
407         return buf.setBytes(index, in, length);
408     }
409 
410     @Override
411     public ByteBuf setZero(int index, int length) {
412         buf.setZero(index, length);
413         return this;
414     }
415 
416     @Override
417     public boolean readBoolean() {
418         return buf.readBoolean();
419     }
420 
421     @Override
422     public byte readByte() {
423         return buf.readByte();
424     }
425 
426     @Override
427     public short readUnsignedByte() {
428         return buf.readUnsignedByte();
429     }
430 
431     @Override
432     public short readShort() {
433         return buf.readShort();
434     }
435 
436     @Override
437     public int readUnsignedShort() {
438         return buf.readUnsignedShort();
439     }
440 
441     @Override
442     public int readMedium() {
443         return buf.readMedium();
444     }
445 
446     @Override
447     public int readUnsignedMedium() {
448         return buf.readUnsignedMedium();
449     }
450 
451     @Override
452     public int readInt() {
453         return buf.readInt();
454     }
455 
456     @Override
457     public long readUnsignedInt() {
458         return buf.readUnsignedInt();
459     }
460 
461     @Override
462     public long readLong() {
463         return buf.readLong();
464     }
465 
466     @Override
467     public char readChar() {
468         return buf.readChar();
469     }
470 
471     @Override
472     public float readFloat() {
473         return buf.readFloat();
474     }
475 
476     @Override
477     public double readDouble() {
478         return buf.readDouble();
479     }
480 
481     @Override
482     public ByteBuf readBytes(int length) {
483         return buf.readBytes(length);
484     }
485 
486     @Override
487     public ByteBuf readSlice(int length) {
488         return buf.readSlice(length);
489     }
490 
491     @Override
492     public ByteBuf readBytes(ByteBuf dst) {
493         buf.readBytes(dst);
494         return this;
495     }
496 
497     @Override
498     public ByteBuf readBytes(ByteBuf dst, int length) {
499         buf.readBytes(dst, length);
500         return this;
501     }
502 
503     @Override
504     public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) {
505         buf.readBytes(dst, dstIndex, length);
506         return this;
507     }
508 
509     @Override
510     public ByteBuf readBytes(byte[] dst) {
511         buf.readBytes(dst);
512         return this;
513     }
514 
515     @Override
516     public ByteBuf readBytes(byte[] dst, int dstIndex, int length) {
517         buf.readBytes(dst, dstIndex, length);
518         return this;
519     }
520 
521     @Override
522     public ByteBuf readBytes(ByteBuffer dst) {
523         buf.readBytes(dst);
524         return this;
525     }
526 
527     @Override
528     public ByteBuf readBytes(OutputStream out, int length) throws IOException {
529         buf.readBytes(out, length);
530         return this;
531     }
532 
533     @Override
534     public int readBytes(GatheringByteChannel out, int length) throws IOException {
535         return buf.readBytes(out, length);
536     }
537 
538     @Override
539     public ByteBuf skipBytes(int length) {
540         buf.skipBytes(length);
541         return this;
542     }
543 
544     @Override
545     public ByteBuf writeBoolean(boolean value) {
546         buf.writeBoolean(value);
547         return this;
548     }
549 
550     @Override
551     public ByteBuf writeByte(int value) {
552         buf.writeByte(value);
553         return this;
554     }
555 
556     @Override
557     public ByteBuf writeShort(int value) {
558         buf.writeShort(value);
559         return this;
560     }
561 
562     @Override
563     public ByteBuf writeMedium(int value) {
564         buf.writeMedium(value);
565         return this;
566     }
567 
568     @Override
569     public ByteBuf writeInt(int value) {
570         buf.writeInt(value);
571         return this;
572     }
573 
574     @Override
575     public ByteBuf writeLong(long value) {
576         buf.writeLong(value);
577         return this;
578     }
579 
580     @Override
581     public ByteBuf writeChar(int value) {
582         buf.writeChar(value);
583         return this;
584     }
585 
586     @Override
587     public ByteBuf writeFloat(float value) {
588         buf.writeFloat(value);
589         return this;
590     }
591 
592     @Override
593     public ByteBuf writeDouble(double value) {
594         buf.writeDouble(value);
595         return this;
596     }
597 
598     @Override
599     public ByteBuf writeBytes(ByteBuf src) {
600         buf.writeBytes(src);
601         return this;
602     }
603 
604     @Override
605     public ByteBuf writeBytes(ByteBuf src, int length) {
606         buf.writeBytes(src, length);
607         return this;
608     }
609 
610     @Override
611     public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) {
612         buf.writeBytes(src, srcIndex, length);
613         return this;
614     }
615 
616     @Override
617     public ByteBuf writeBytes(byte[] src) {
618         buf.writeBytes(src);
619         return this;
620     }
621 
622     @Override
623     public ByteBuf writeBytes(byte[] src, int srcIndex, int length) {
624         buf.writeBytes(src, srcIndex, length);
625         return this;
626     }
627 
628     @Override
629     public ByteBuf writeBytes(ByteBuffer src) {
630         buf.writeBytes(src);
631         return this;
632     }
633 
634     @Override
635     public int writeBytes(InputStream in, int length) throws IOException {
636         return buf.writeBytes(in, length);
637     }
638 
639     @Override
640     public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
641         return buf.writeBytes(in, length);
642     }
643 
644     @Override
645     public ByteBuf writeZero(int length) {
646         buf.writeZero(length);
647         return this;
648     }
649 
650     @Override
651     public int indexOf(int fromIndex, int toIndex, byte value) {
652         return buf.indexOf(fromIndex, toIndex, value);
653     }
654 
655     @Override
656     public int bytesBefore(byte value) {
657         return buf.bytesBefore(value);
658     }
659 
660     @Override
661     public int bytesBefore(int length, byte value) {
662         return buf.bytesBefore(length, value);
663     }
664 
665     @Override
666     public int bytesBefore(int index, int length, byte value) {
667         return buf.bytesBefore(index, length, value);
668     }
669 
670     @Override
671     public int forEachByte(ByteBufProcessor processor) {
672         return buf.forEachByte(processor);
673     }
674 
675     @Override
676     public int forEachByte(int index, int length, ByteBufProcessor processor) {
677         return buf.forEachByte(index, length, processor);
678     }
679 
680     @Override
681     public int forEachByteDesc(ByteBufProcessor processor) {
682         return buf.forEachByteDesc(processor);
683     }
684 
685     @Override
686     public int forEachByteDesc(int index, int length, ByteBufProcessor processor) {
687         return buf.forEachByteDesc(index, length, processor);
688     }
689 
690     @Override
691     public ByteBuf copy() {
692         return buf.copy();
693     }
694 
695     @Override
696     public ByteBuf copy(int index, int length) {
697         return buf.copy(index, length);
698     }
699 
700     @Override
701     public ByteBuf slice() {
702         return buf.slice();
703     }
704 
705     @Override
706     public ByteBuf slice(int index, int length) {
707         return buf.slice(index, length);
708     }
709 
710     @Override
711     public ByteBuf duplicate() {
712         return buf.duplicate();
713     }
714 
715     @Override
716     public int nioBufferCount() {
717         return buf.nioBufferCount();
718     }
719 
720     @Override
721     public ByteBuffer nioBuffer() {
722         return buf.nioBuffer();
723     }
724 
725     @Override
726     public ByteBuffer nioBuffer(int index, int length) {
727         return buf.nioBuffer(index, length);
728     }
729 
730     @Override
731     public ByteBuffer[] nioBuffers() {
732         return buf.nioBuffers();
733     }
734 
735     @Override
736     public ByteBuffer[] nioBuffers(int index, int length) {
737         return buf.nioBuffers(index, length);
738     }
739 
740     @Override
741     public ByteBuffer internalNioBuffer(int index, int length) {
742         return buf.internalNioBuffer(index, length);
743     }
744 
745     @Override
746     public boolean hasArray() {
747         return buf.hasArray();
748     }
749 
750     @Override
751     public byte[] array() {
752         return buf.array();
753     }
754 
755     @Override
756     public int arrayOffset() {
757         return buf.arrayOffset();
758     }
759 
760     @Override
761     public String toString(Charset charset) {
762         return buf.toString(charset);
763     }
764 
765     @Override
766     public String toString(int index, int length, Charset charset) {
767         return buf.toString(index, length, charset);
768     }
769 
770     @Override
771     public int hashCode() {
772         return buf.hashCode();
773     }
774 
775     @Override
776     @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
777     public boolean equals(Object obj) {
778         return buf.equals(obj);
779     }
780 
781     @Override
782     public int compareTo(ByteBuf buffer) {
783         return buf.compareTo(buffer);
784     }
785 
786     @Override
787     public String toString() {
788         return StringUtil.simpleClassName(this) + '(' + buf.toString() + ')';
789     }
790 
791     @Override
792     public ByteBuf retain(int increment) {
793         buf.retain(increment);
794         return this;
795     }
796 
797     @Override
798     public ByteBuf retain() {
799         buf.retain();
800         return this;
801     }
802 
803     @Override
804     public ByteBuf touch() {
805         buf.touch();
806         return this;
807     }
808 
809     @Override
810     public ByteBuf touch(Object hint) {
811         buf.touch(hint);
812         return this;
813     }
814 
815     @Override
816     public boolean isReadable(int size) {
817         return buf.isReadable(size);
818     }
819 
820     @Override
821     public boolean isWritable(int size) {
822         return buf.isWritable(size);
823     }
824 
825     @Override
826     public int refCnt() {
827         return buf.refCnt();
828     }
829 
830     @Override
831     public boolean release() {
832         return buf.release();
833     }
834 
835     @Override
836     public boolean release(int decrement) {
837         return buf.release(decrement);
838     }
839 }