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