1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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")
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 String readString(int length, Charset charset) {
717 checkReadableBytes(length);
718 return buffer.readString(length, charset);
719 }
720
721 @Override
722 public ByteBuf resetReaderIndex() {
723 buffer.resetReaderIndex();
724 return this;
725 }
726
727 @Override
728 public ByteBuf resetWriterIndex() {
729 throw reject();
730 }
731
732 @Override
733 public ByteBuf setBoolean(int index, boolean value) {
734 throw reject();
735 }
736
737 @Override
738 public ByteBuf setByte(int index, int value) {
739 throw reject();
740 }
741
742 @Override
743 public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
744 throw reject();
745 }
746
747 @Override
748 public ByteBuf setBytes(int index, byte[] src) {
749 throw reject();
750 }
751
752 @Override
753 public ByteBuf setBytes(int index, ByteBuffer src) {
754 throw reject();
755 }
756
757 @Override
758 public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
759 throw reject();
760 }
761
762 @Override
763 public ByteBuf setBytes(int index, ByteBuf src, int length) {
764 throw reject();
765 }
766
767 @Override
768 public ByteBuf setBytes(int index, ByteBuf src) {
769 throw reject();
770 }
771
772 @Override
773 public int setBytes(int index, InputStream in, int length) {
774 throw reject();
775 }
776
777 @Override
778 public ByteBuf setZero(int index, int length) {
779 throw reject();
780 }
781
782 @Override
783 public int setBytes(int index, ScatteringByteChannel in, int length) {
784 throw reject();
785 }
786
787 @Override
788 public int setBytes(int index, FileChannel in, long position, int length) {
789 throw reject();
790 }
791
792 @Override
793 public ByteBuf setIndex(int readerIndex, int writerIndex) {
794 throw reject();
795 }
796
797 @Override
798 public ByteBuf setInt(int index, int value) {
799 throw reject();
800 }
801
802 @Override
803 public ByteBuf setIntLE(int index, int value) {
804 throw reject();
805 }
806
807 @Override
808 public ByteBuf setLong(int index, long value) {
809 throw reject();
810 }
811
812 @Override
813 public ByteBuf setLongLE(int index, long value) {
814 throw reject();
815 }
816
817 @Override
818 public ByteBuf setMedium(int index, int value) {
819 throw reject();
820 }
821
822 @Override
823 public ByteBuf setMediumLE(int index, int value) {
824 throw reject();
825 }
826
827 @Override
828 public ByteBuf setShort(int index, int value) {
829 throw reject();
830 }
831
832 @Override
833 public ByteBuf setShortLE(int index, int value) {
834 throw reject();
835 }
836
837 @Override
838 public ByteBuf setChar(int index, int value) {
839 throw reject();
840 }
841
842 @Override
843 public ByteBuf setFloat(int index, float value) {
844 throw reject();
845 }
846
847 @Override
848 public ByteBuf setDouble(int index, double value) {
849 throw reject();
850 }
851
852 @Override
853 public ByteBuf skipBytes(int length) {
854 checkReadableBytes(length);
855 buffer.skipBytes(length);
856 return this;
857 }
858
859 @Override
860 public ByteBuf slice() {
861 throw reject();
862 }
863
864 @Override
865 public ByteBuf retainedSlice() {
866 throw reject();
867 }
868
869 @Override
870 public ByteBuf slice(int index, int length) {
871 checkIndex(index, length);
872 return buffer.slice(index, length);
873 }
874
875 @Override
876 public ByteBuf retainedSlice(int index, int length) {
877 checkIndex(index, length);
878 return buffer.retainedSlice(index, length);
879 }
880
881 @Override
882 public int nioBufferCount() {
883 return buffer.nioBufferCount();
884 }
885
886 @Override
887 public ByteBuffer nioBuffer() {
888 throw reject();
889 }
890
891 @Override
892 public ByteBuffer nioBuffer(int index, int length) {
893 checkIndex(index, length);
894 return buffer.nioBuffer(index, length);
895 }
896
897 @Override
898 public ByteBuffer[] nioBuffers() {
899 throw reject();
900 }
901
902 @Override
903 public ByteBuffer[] nioBuffers(int index, int length) {
904 checkIndex(index, length);
905 return buffer.nioBuffers(index, length);
906 }
907
908 @Override
909 public ByteBuffer internalNioBuffer(int index, int length) {
910 checkIndex(index, length);
911 return buffer.internalNioBuffer(index, length);
912 }
913
914 @Override
915 public String toString(int index, int length, Charset charset) {
916 checkIndex(index, length);
917 return buffer.toString(index, length, charset);
918 }
919
920 @Override
921 public String toString(Charset charsetName) {
922 throw reject();
923 }
924
925 @Override
926 public String toString() {
927 return StringUtil.simpleClassName(this) + '(' +
928 "ridx=" +
929 readerIndex() +
930 ", " +
931 "widx=" +
932 writerIndex() +
933 ')';
934 }
935
936 @Override
937 public boolean isWritable() {
938 return false;
939 }
940
941 @Override
942 public boolean isWritable(int size) {
943 return false;
944 }
945
946 @Override
947 public int writableBytes() {
948 return 0;
949 }
950
951 @Override
952 public int maxWritableBytes() {
953 return 0;
954 }
955
956 @Override
957 public ByteBuf writeBoolean(boolean value) {
958 throw reject();
959 }
960
961 @Override
962 public ByteBuf writeByte(int value) {
963 throw reject();
964 }
965
966 @Override
967 public ByteBuf writeBytes(byte[] src, int srcIndex, int length) {
968 throw reject();
969 }
970
971 @Override
972 public ByteBuf writeBytes(byte[] src) {
973 throw reject();
974 }
975
976 @Override
977 public ByteBuf writeBytes(ByteBuffer src) {
978 throw reject();
979 }
980
981 @Override
982 public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) {
983 throw reject();
984 }
985
986 @Override
987 public ByteBuf writeBytes(ByteBuf src, int length) {
988 throw reject();
989 }
990
991 @Override
992 public ByteBuf writeBytes(ByteBuf src) {
993 throw reject();
994 }
995
996 @Override
997 public int writeBytes(InputStream in, int length) {
998 throw reject();
999 }
1000
1001 @Override
1002 public int writeBytes(ScatteringByteChannel in, int length) {
1003 throw reject();
1004 }
1005
1006 @Override
1007 public int writeBytes(FileChannel in, long position, int length) {
1008 throw reject();
1009 }
1010
1011 @Override
1012 public ByteBuf writeInt(int value) {
1013 throw reject();
1014 }
1015
1016 @Override
1017 public ByteBuf writeIntLE(int value) {
1018 throw reject();
1019 }
1020
1021 @Override
1022 public ByteBuf writeLong(long value) {
1023 throw reject();
1024 }
1025
1026 @Override
1027 public ByteBuf writeLongLE(long value) {
1028 throw reject();
1029 }
1030
1031 @Override
1032 public ByteBuf writeMedium(int value) {
1033 throw reject();
1034 }
1035
1036 @Override
1037 public ByteBuf writeMediumLE(int value) {
1038 throw reject();
1039 }
1040
1041 @Override
1042 public ByteBuf writeZero(int length) {
1043 throw reject();
1044 }
1045
1046 @Override
1047 public int writerIndex() {
1048 return buffer.writerIndex();
1049 }
1050
1051 @Override
1052 public ByteBuf writerIndex(int writerIndex) {
1053 throw reject();
1054 }
1055
1056 @Override
1057 public ByteBuf writeShort(int value) {
1058 throw reject();
1059 }
1060
1061 @Override
1062 public ByteBuf writeShortLE(int value) {
1063 throw reject();
1064 }
1065
1066 @Override
1067 public ByteBuf writeChar(int value) {
1068 throw reject();
1069 }
1070
1071 @Override
1072 public ByteBuf writeFloat(float value) {
1073 throw reject();
1074 }
1075
1076 @Override
1077 public ByteBuf writeDouble(double value) {
1078 throw reject();
1079 }
1080
1081 @Override
1082 public int setCharSequence(int index, CharSequence sequence, Charset charset) {
1083 throw reject();
1084 }
1085
1086 @Override
1087 public int writeCharSequence(CharSequence sequence, Charset charset) {
1088 throw reject();
1089 }
1090
1091 private void checkIndex(int index, int length) {
1092 if (index + length > buffer.writerIndex()) {
1093 throw REPLAY;
1094 }
1095 }
1096
1097 private void checkReadableBytes(int readableBytes) {
1098 if (buffer.readableBytes() < readableBytes) {
1099 throw REPLAY;
1100 }
1101 }
1102
1103 @Override
1104 public ByteBuf discardSomeReadBytes() {
1105 throw reject();
1106 }
1107
1108 @Override
1109 public int refCnt() {
1110 return buffer.refCnt();
1111 }
1112
1113 @Override
1114 public ByteBuf retain() {
1115 throw reject();
1116 }
1117
1118 @Override
1119 public ByteBuf retain(int increment) {
1120 throw reject();
1121 }
1122
1123 @Override
1124 public ByteBuf touch() {
1125 buffer.touch();
1126 return this;
1127 }
1128
1129 @Override
1130 public ByteBuf touch(Object hint) {
1131 buffer.touch(hint);
1132 return this;
1133 }
1134
1135 @Override
1136 public boolean release() {
1137 throw reject();
1138 }
1139
1140 @Override
1141 public boolean release(int decrement) {
1142 throw reject();
1143 }
1144
1145 @Override
1146 public ByteBuf unwrap() {
1147 throw reject();
1148 }
1149
1150 private static UnsupportedOperationException reject() {
1151 return new UnsupportedOperationException("not a replayable operation");
1152 }
1153 }