@@ -130,31 +130,11 @@ static boolean isValidUtf8(byte[] bytes) {
130130 * Returns {@code true} if the given byte array slice is a well-formed UTF-8 byte sequence. The
131131 * range of bytes to be checked extends from index {@code index}, inclusive, to {@code limit},
132132 * exclusive.
133- *
134- * <p>This is a convenience method, equivalent to {@code partialIsValidUtf8(bytes, index, limit)
135- * == Utf8.COMPLETE}.
136133 */
137134 static boolean isValidUtf8 (byte [] bytes , int index , int limit ) {
138135 return processor .isValidUtf8 (bytes , index , limit );
139136 }
140137
141- /**
142- * Tells whether the given byte array slice is a well-formed, malformed, or incomplete UTF-8 byte
143- * sequence. The range of bytes to be checked extends from index {@code index}, inclusive, to
144- * {@code limit}, exclusive.
145- *
146- * @param state either {@link Utf8#COMPLETE} (if this is the initial decoding operation) or the
147- * value returned from a call to a partial decoding method for the previous bytes
148- * @return {@link #MALFORMED} if the partial byte sequence is definitely not well-formed, {@link
149- * #COMPLETE} if it is well-formed (no additional input needed), or if the byte sequence is
150- * "incomplete", i.e. apparently terminated in the middle of a character, an opaque integer
151- * "state" value containing enough information to decode the character when passed to a
152- * subsequent invocation of a partial decoding method.
153- */
154- static int partialIsValidUtf8 (int state , byte [] bytes , int index , int limit ) {
155- return processor .partialIsValidUtf8 (state , bytes , index , limit );
156- }
157-
158138 private static int incompleteStateFor (int byte1 ) {
159139 return (byte1 > (byte ) 0xF4 ) ? MALFORMED : byte1 ;
160140 }
@@ -292,19 +272,6 @@ static boolean isValidUtf8(ByteBuffer buffer) {
292272 return processor .isValidUtf8 (buffer , buffer .position (), buffer .remaining ());
293273 }
294274
295- /**
296- * Determines if the given {@link ByteBuffer} is a partially valid UTF-8 string.
297- *
298- * <p>Selects an optimal algorithm based on the type of {@link ByteBuffer} (i.e. heap or direct)
299- * and the capabilities of the platform.
300- *
301- * @param buffer the buffer to check.
302- * @see Utf8#partialIsValidUtf8(int, byte[], int, int)
303- */
304- static int partialIsValidUtf8 (int state , ByteBuffer buffer , int index , int limit ) {
305- return processor .partialIsValidUtf8 (state , buffer , index , limit );
306- }
307-
308275 /**
309276 * Decodes the given UTF-8 portion of the {@link ByteBuffer} into a {@link String}.
310277 *
@@ -388,7 +355,7 @@ final boolean isValidUtf8(byte[] bytes, int index, int limit) {
388355 * "state" value containing enough information to decode the character when passed to a
389356 * subsequent invocation of a partial decoding method.
390357 */
391- abstract int partialIsValidUtf8 (int state , byte [] bytes , int index , int limit );
358+ protected abstract int partialIsValidUtf8 (int state , byte [] bytes , int index , int limit );
392359
393360 /**
394361 * Returns {@code true} if the given portion of the {@link ByteBuffer} is a well-formed UTF-8
@@ -420,15 +387,15 @@ final int partialIsValidUtf8(
420387 }
421388
422389 /** Performs validation for direct {@link ByteBuffer} instances. */
423- abstract int partialIsValidUtf8Direct (
390+ protected abstract int partialIsValidUtf8Direct (
424391 final int state , final ByteBuffer buffer , int index , final int limit );
425392
426393 /**
427394 * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
428395 * than potentially faster approaches. This first completes validation for the current character
429396 * (provided by {@code state}) and then finishes validation for the sequence.
430397 */
431- final int partialIsValidUtf8Default (
398+ protected final int partialIsValidUtf8Default (
432399 final int state , final ByteBuffer buffer , int index , final int limit ) {
433400 if (state != COMPLETE ) {
434401 // The previous decoding operation was incomplete (or malformed).
@@ -783,7 +750,7 @@ final void encodeUtf8(String in, ByteBuffer out) {
783750 /** {@link Processor} implementation that does not use any {@code sun.misc.Unsafe} methods. */
784751 static final class SafeProcessor extends Processor {
785752 @ Override
786- int partialIsValidUtf8 (int state , byte [] bytes , int index , int limit ) {
753+ protected int partialIsValidUtf8 (int state , byte [] bytes , int index , int limit ) {
787754 if (state != COMPLETE ) {
788755 // The previous decoding operation was incomplete (or malformed).
789756 // We look for a well-formed sequence consisting of bytes from
@@ -871,7 +838,7 @@ int partialIsValidUtf8(int state, byte[] bytes, int index, int limit) {
871838 }
872839
873840 @ Override
874- int partialIsValidUtf8Direct (int state , ByteBuffer buffer , int index , int limit ) {
841+ protected int partialIsValidUtf8Direct (int state , ByteBuffer buffer , int index , int limit ) {
875842 // For safe processing, we have to use the ByteBuffer API.
876843 return partialIsValidUtf8Default (state , buffer , index , limit );
877844 }
@@ -1163,7 +1130,7 @@ static boolean isAvailable() {
11631130 }
11641131
11651132 @ Override
1166- int partialIsValidUtf8 (int state , byte [] bytes , final int index , final int limit ) {
1133+ protected int partialIsValidUtf8 (int state , byte [] bytes , final int index , final int limit ) {
11671134 // Bitwise OR combines the sign bits so any negative value fails the check.
11681135 if ((index | limit | bytes .length - limit ) < 0 ) {
11691136 throw new ArrayIndexOutOfBoundsException (
@@ -1258,7 +1225,7 @@ int partialIsValidUtf8(int state, byte[] bytes, final int index, final int limit
12581225 }
12591226
12601227 @ Override
1261- int partialIsValidUtf8Direct (
1228+ protected int partialIsValidUtf8Direct (
12621229 final int state , ByteBuffer buffer , final int index , final int limit ) {
12631230 // Bitwise OR combines the sign bits so any negative value fails the check.
12641231 if ((index | limit | buffer .limit () - limit ) < 0 ) {
0 commit comments