public static int computeTruncatedLength(Slice slice, int offset, int length, int maxCodePointCount, boolean isCharType) { if (isCharType) { // truncate the characters and then remove the trailing white spaces return byteCountWithoutTrailingSpace(slice, offset, length, maxCodePointCount); } if (maxCodePointCount >= 0 && length > maxCodePointCount) { return byteCount(slice, offset, length, maxCodePointCount); } return length; }
public static int computeTruncatedLength(Slice slice, int offset, int length, int maxCodePointCount, boolean isCharType) { if (isCharType) { // truncate the characters and then remove the trailing white spaces return byteCountWithoutTrailingSpace(slice, offset, length, maxCodePointCount); } if (maxCodePointCount >= 0 && length > maxCodePointCount) { return byteCount(slice, offset, length, maxCodePointCount); } return length; }
public static int byteCountWithoutTrailingSpace(Slice slice, int offset, int length, int codePointCount) { int truncatedLength = byteCount(slice, offset, length, codePointCount); return byteCountWithoutTrailingSpace(slice, offset, truncatedLength); }
public static Slice trimTrailingSpaces(Slice slice) { requireNonNull(slice, "slice is null"); return slice.slice(0, byteCountWithoutTrailingSpace(slice, 0, slice.length())); }
private static void assertByteCountWithoutTrailingSpaceFailure(String string, int offset, int maxLength) { try { byteCountWithoutTrailingSpace(utf8Slice(string), offset, maxLength); fail("Expected exception"); } catch (IllegalArgumentException expected) { } }
private static void assertByteCountWithoutTrailingSpaceFailure(String string, int offset, int maxLength) { try { byteCountWithoutTrailingSpace(utf8Slice(string), offset, maxLength); fail("Expected exception"); } catch (IllegalArgumentException expected) { } }
private static void assertByteCountWithoutTrailingSpace(byte[] actual, int offset, int length, byte[] expected) { Slice slice = wrappedBuffer(actual); int trimmedLength = byteCountWithoutTrailingSpace(slice, offset, length); byte[] bytes = slice.getBytes(offset, trimmedLength); assertEquals(bytes, expected); }
private static void assertByteCountWithoutTrailingSpace(byte[] actual, int offset, int length, int codePointCount, byte[] expected) { Slice slice = wrappedBuffer(actual); int truncatedLength = byteCountWithoutTrailingSpace(slice, offset, length, codePointCount); byte[] bytes = slice.getBytes(offset, truncatedLength); assertEquals(bytes, expected); } }
private static void assertByteCountWithoutTrailingSpace(byte[] actual, int offset, int length, int codePointCount, byte[] expected) { Slice slice = wrappedBuffer(actual); int truncatedLength = byteCountWithoutTrailingSpace(slice, offset, length, codePointCount); byte[] bytes = slice.getBytes(offset, truncatedLength); assertEquals(bytes, expected); } }
private static void assertByteCountWithoutTrailingSpace(byte[] actual, int offset, int length, byte[] expected) { Slice slice = wrappedBuffer(actual); int trimmedLength = byteCountWithoutTrailingSpace(slice, offset, length); byte[] bytes = slice.getBytes(offset, trimmedLength); assertEquals(bytes, expected); }