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