2525import java .io .Serializable ;
2626import java .net .URI ;
2727import java .net .URISyntaxException ;
28- import java .nio .charset .Charset ;
2928import java .nio .charset .StandardCharsets ;
3029import java .util .Arrays ;
3130import java .util .Collections ;
@@ -460,24 +459,14 @@ private String canonicalize(boolean coordinatesOnly) {
460459 return purl .toString ();
461460 }
462461
463- /**
464- * Encodes the input in conformance with RFC 3986.
465- *
466- * @param input the String to encode
467- * @return an encoded String
468- */
469- private String percentEncode (final String input ) {
470- return uriEncode (input , StandardCharsets .UTF_8 );
471- }
472-
473- private static String uriEncode (String source , Charset charset ) {
462+ private static String percentEncode (final String source ) {
474463 if (source == null || source .isEmpty ()) {
475464 return source ;
476465 }
477466
478- byte [] bytes = source .getBytes (charset );
467+ byte [] bytes = source .getBytes (StandardCharsets . UTF_8 );
479468 int length = bytes .length ;
480- int pos = indexOfFirstUnreservedChar (bytes );
469+ int pos = indexOfFirstUnsafeChar (bytes );
481470
482471 if (pos == -1 ) {
483472 return source ;
@@ -500,7 +489,7 @@ private static String uriEncode(String source, Charset charset) {
500489 return builder .toString ();
501490 }
502491
503- private static int indexOfFirstUnreservedChar (final byte [] bytes ) {
492+ private static int indexOfFirstUnsafeChar (final byte [] bytes ) {
504493 final int length = bytes .length ;
505494 int pos = -1 ;
506495
@@ -573,23 +562,14 @@ private static String toLowerCase(String s) {
573562 return new String (chars );
574563 }
575564
576- /**
577- * Optionally decodes a String, if it's encoded. If String is not encoded,
578- * method will return the original input value.
579- *
580- * @param input the value String to decode
581- * @return a decoded String
582- */
583- private String percentDecode (final String input ) {
584- return uriDecode (input );
585- }
586-
587- public static String uriDecode (String source ) {
565+ public static String percentDecode (final String source ) {
588566 if (source == null || source .isEmpty ()) {
589567 return source ;
590568 }
591569
592- if (source .indexOf ('%' ) == -1 ) {
570+ int firstPercent = source .indexOf ('%' );
571+
572+ if (firstPercent == -1 ) {
593573 return source ;
594574 }
595575
0 commit comments