@Test public void testIsTextWithInvalidIndexAndLength() { ByteBuf buffer = Unpooled.buffer(); try { buffer.writeBytes(new byte[4]); int[][] validIndexLengthPairs = { {4, 0}, {0, 4}, {1, 3}, }; for (int[] pair : validIndexLengthPairs) { assertTrue(ByteBufUtil.isText(buffer, pair[0], pair[1], CharsetUtil.US_ASCII)); } int[][] invalidIndexLengthPairs = { {4, 1}, {-1, 2}, {3, -1}, {3, -2}, {5, 0}, {1, 5}, }; for (int[] pair : invalidIndexLengthPairs) { try { ByteBufUtil.isText(buffer, pair[0], pair[1], CharsetUtil.US_ASCII); fail("Expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } } } finally { buffer.release(); } }
public static boolean isText(ByteBuf buf, Charset charset) { return isText(buf, buf.readerIndex(), buf.readableBytes(), charset); }
ByteBufUtil { public static boolean isText(ByteBuf buf, Charset charset) { return isText(buf, buf.readerIndex(), buf.readableBytes(), charset); } }
ByteBufUtil { public static boolean isText(ByteBuf buf, Charset charset) { return isText(buf, buf.readerIndex(), buf.readableBytes(), charset); } private  ByteBufUtil(); }
ByteBufUtil { public static boolean isText(ByteBuf buf, Charset charset) { return isText(buf, buf.readerIndex(), buf.readableBytes(), charset); } private  ByteBufUtil(); static String hexDump(ByteBuf buffer); static String hexDump(ByteBuf buffer, int fromIndex, int length); static String hexDump(byte[] array); static String hexDump(byte[] array, int fromIndex, int length); static byte decodeHexByte(CharSequence s, int pos); static byte[] decodeHexDump(CharSequence hexDump); static byte[] decodeHexDump(CharSequence hexDump, int fromIndex, int length); static boolean ensureWritableSuccess(int ensureWritableResult); static int hashCode(ByteBuf buffer); static int indexOf(ByteBuf needle, ByteBuf haystack); static boolean equals(ByteBuf a, int aStartIndex, ByteBuf b, int bStartIndex, int length); static boolean equals(ByteBuf bufferA, ByteBuf bufferB); static int compare(ByteBuf bufferA, ByteBuf bufferB); static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value); static short swapShort(short value); static int swapMedium(int value); static int swapInt(int value); static long swapLong(long value); @SuppressWarnings("deprecation") static ByteBuf writeShortBE(ByteBuf buf, int shortValue); @SuppressWarnings("deprecation") static ByteBuf setShortBE(ByteBuf buf, int index, int shortValue); @SuppressWarnings("deprecation") static ByteBuf writeMediumBE(ByteBuf buf, int mediumValue); static ByteBuf readBytes(ByteBufAllocator alloc, ByteBuf buffer, int length); static ByteBuf writeUtf8(ByteBufAllocator alloc, CharSequence seq); static int writeUtf8(ByteBuf buf, CharSequence seq); static int reserveAndWriteUtf8(ByteBuf buf, CharSequence seq, int reserveBytes); static int utf8MaxBytes(final int seqLength); static int utf8MaxBytes(CharSequence seq); static int utf8Bytes(final CharSequence seq); static ByteBuf writeAscii(ByteBufAllocator alloc, CharSequence seq); static int writeAscii(ByteBuf buf, CharSequence seq); static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset); static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset, int extraCapacity); static ByteBuf threadLocalDirectBuffer(); static byte[] getBytes(ByteBuf buf); static byte[] getBytes(ByteBuf buf, int start, int length); static byte[] getBytes(ByteBuf buf, int start, int length, boolean copy); static void copy(AsciiString src, ByteBuf dst); static void copy(AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length); static void copy(AsciiString src, int srcIdx, ByteBuf dst, int length); static String prettyHexDump(ByteBuf buffer); static String prettyHexDump(ByteBuf buffer, int offset, int length); static void appendPrettyHexDump(StringBuilder dump, ByteBuf buf); static void appendPrettyHexDump(StringBuilder dump, ByteBuf buf, int offset, int length); static boolean isText(ByteBuf buf, Charset charset); static boolean isText(ByteBuf buf, int index, int length, Charset charset); }
ByteBufUtil { public static boolean isText(ByteBuf buf, Charset charset) { return isText(buf, buf.readerIndex(), buf.readableBytes(), charset); } private  ByteBufUtil(); static String hexDump(ByteBuf buffer); static String hexDump(ByteBuf buffer, int fromIndex, int length); static String hexDump(byte[] array); static String hexDump(byte[] array, int fromIndex, int length); static byte decodeHexByte(CharSequence s, int pos); static byte[] decodeHexDump(CharSequence hexDump); static byte[] decodeHexDump(CharSequence hexDump, int fromIndex, int length); static boolean ensureWritableSuccess(int ensureWritableResult); static int hashCode(ByteBuf buffer); static int indexOf(ByteBuf needle, ByteBuf haystack); static boolean equals(ByteBuf a, int aStartIndex, ByteBuf b, int bStartIndex, int length); static boolean equals(ByteBuf bufferA, ByteBuf bufferB); static int compare(ByteBuf bufferA, ByteBuf bufferB); static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value); static short swapShort(short value); static int swapMedium(int value); static int swapInt(int value); static long swapLong(long value); @SuppressWarnings("deprecation") static ByteBuf writeShortBE(ByteBuf buf, int shortValue); @SuppressWarnings("deprecation") static ByteBuf setShortBE(ByteBuf buf, int index, int shortValue); @SuppressWarnings("deprecation") static ByteBuf writeMediumBE(ByteBuf buf, int mediumValue); static ByteBuf readBytes(ByteBufAllocator alloc, ByteBuf buffer, int length); static ByteBuf writeUtf8(ByteBufAllocator alloc, CharSequence seq); static int writeUtf8(ByteBuf buf, CharSequence seq); static int reserveAndWriteUtf8(ByteBuf buf, CharSequence seq, int reserveBytes); static int utf8MaxBytes(final int seqLength); static int utf8MaxBytes(CharSequence seq); static int utf8Bytes(final CharSequence seq); static ByteBuf writeAscii(ByteBufAllocator alloc, CharSequence seq); static int writeAscii(ByteBuf buf, CharSequence seq); static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset); static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset, int extraCapacity); static ByteBuf threadLocalDirectBuffer(); static byte[] getBytes(ByteBuf buf); static byte[] getBytes(ByteBuf buf, int start, int length); static byte[] getBytes(ByteBuf buf, int start, int length, boolean copy); static void copy(AsciiString src, ByteBuf dst); static void copy(AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length); static void copy(AsciiString src, int srcIdx, ByteBuf dst, int length); static String prettyHexDump(ByteBuf buffer); static String prettyHexDump(ByteBuf buffer, int offset, int length); static void appendPrettyHexDump(StringBuilder dump, ByteBuf buf); static void appendPrettyHexDump(StringBuilder dump, ByteBuf buf, int offset, int length); static boolean isText(ByteBuf buf, Charset charset); static boolean isText(ByteBuf buf, int index, int length, Charset charset);  }