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