Skip to content

Commit 06529d5

Browse files
committed
Rename some new methods and fix Javadoc links
1 parent 72c8e35 commit 06529d5

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public Base64 get() {
111111
}
112112

113113
/**
114-
* Sets the format of the decoding table. This method allows to explicitly state whether a "standard" or "URL Safe" Base64 decoding is expected. This
115-
* method does not modify behavior on encoding operations. For configuration of the encoding behavior, please use {@link #setUrlSafe} method.
114+
* Sets the format of the decoding table. This method allows to explicitly state whether a standard or URL-safe Base64 decoding is expected. This method
115+
* does not modify behavior on encoding operations. For configuration of the encoding behavior, please use {@link #setUrlSafe(boolean)} method.
116116
* <p>
117117
* By default, the implementation uses the {@link DecodeTableFormat#MIXED} approach, allowing a seamless handling of both
118118
* {@link DecodeTableFormat#URL_SAFE} and {@link DecodeTableFormat#STANDARD} base64.
@@ -147,8 +147,8 @@ public Builder setEncodeTable(final byte... encodeTable) {
147147
/**
148148
* Sets the URL-safe encoding policy.
149149
* <p>
150-
* This method does not modify behavior on decoding operations. For configuration of the decoding behavior, please use {@link #setDecodeTableFormat}
151-
* method.
150+
* This method does not modify behavior on decoding operations. For configuration of the decoding behavior, please use
151+
* {@link #setDecodeTableFormat(DecodeTableFormat)} method.
152152
* </p>
153153
*
154154
* @param urlSafe URL-safe encoding policy, null resets to the default.
@@ -172,13 +172,13 @@ public Builder setUrlSafe(final boolean urlSafe) {
172172
public enum DecodeTableFormat {
173173

174174
/**
175-
* Corresponds to the "standard" Base64 coding table, as specified in
175+
* Corresponds to the standard Base64 coding table, as specified in
176176
* <a href="https://www.ietf.org/rfc/rfc2045#:~:text=Table%201%3A%20The%20Base64%20Alphabet">RFC 2045 Table 1: The Base64 Alphabet</a>.
177177
*/
178178
STANDARD,
179179

180180
/**
181-
* Corresponds to the "URL Safe" Base64 coding table, as specified in
181+
* Corresponds to the URL-safe Base64 coding table, as specified in
182182
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#:~:text=Table%202%3A%20The%20%22URL%20and%20Filename%20safe%22%20Base%2064%20Alphabet">RFC
183183
* 4648 Table 2: The "URL and Filename safe" Base 64 Alphabet</a>.
184184
*/
@@ -235,7 +235,7 @@ public enum DecodeTableFormat {
235235
/**
236236
* This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in
237237
* <a href="https://www.ietf.org/rfc/rfc2045#:~:text=Table%201%3A%20The%20Base64%20Alphabet">RFC 2045 Table 1: The Base64 Alphabet</a>) into their 6-bit
238-
* positive integer equivalents. Characters that are not in the Base64 or Base64 URL Safe alphabets but fall within the bounds of the array are translated
238+
* positive integer equivalents. Characters that are not in the Base64 or Base64 URL-safe alphabets but fall within the bounds of the array are translated
239239
* to -1.
240240
* <p>
241241
* The characters '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both URL_SAFE and STANDARD base64.
@@ -261,7 +261,7 @@ public enum DecodeTableFormat {
261261
* This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in
262262
* <a href="https://www.ietf.org/rfc/rfc2045#:~:text=Table%201%3A%20The%20Base64%20Alphabet">RFC 2045 Table 1: The Base64 Alphabet</a>) into their 6-bit
263263
* positive integer equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the array are translated to -1. This decoding
264-
* table handles only the "standard" base64 characters, such as '+' and '/'. The "url-safe" characters such as '-' and '_' are not supported by the table.
264+
* table handles only the standard base64 characters, such as '+' and '/'. The "url-safe" characters such as '-' and '_' are not supported by the table.
265265
*/
266266
private static final byte[] STANDARD_DECODE_TABLE = {
267267
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
@@ -276,11 +276,11 @@ public enum DecodeTableFormat {
276276
};
277277

278278
/**
279-
* This array is a lookup table that translates Unicode characters drawn from the "Base64 URL Safe Alphabet" (as specified in
279+
* This array is a lookup table that translates Unicode characters drawn from the "Base64 URL-safe Alphabet" (as specified in
280280
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#:~:text=Table%202%3A%20The%20%22URL%20and%20Filename%20safe%22%20Base%2064%20Alphabet">RFC 4648
281-
* Table 2: The "URL and Filename safe" Base 64 Alphabet</a>) into their 6-bit positive integer equivalents. Characters that are not in the Base64 URL Safe
282-
* alphabet but fall within the bounds of the array are translated to -1. This decoding table handles only the "URL Safe" base64 characters, such as '-' and
283-
* '_'. The "standard" characters such as '+' and '/' are not supported by the table.
281+
* Table 2: The "URL and Filename safe" Base 64 Alphabet</a>) into their 6-bit positive integer equivalents. Characters that are not in the Base64 URL-safe
282+
* alphabet but fall within the bounds of the array are translated to -1. This decoding table handles only the URL-safe base64 characters, such as '-' and
283+
* '_'. The standard characters such as '+' and '/' are not supported by the table.
284284
*/
285285
private static final byte[] URL_SAFE_DECODE_TABLE = {
286286
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
@@ -353,8 +353,9 @@ private static byte[] calculateDecodeTable(final byte[] encodeTable) {
353353
/**
354354
* Decodes Base64 data into octets.
355355
* <p>
356-
* This method seamlessly handles data encoded in URL-safe or normal mode. For enforcing verification against strict standard Base64 or Base64 URL Safe
357-
* tables, please use {@link #decodeBase64Standard} or {@link #decodeBase64Url} methods respectively. This method skips any unknown or not supported bytes.
356+
* This method seamlessly handles data encoded in URL-safe or normal mode. For enforcing verification against strict standard Base64 or Base64 URL-safe
357+
* tables, please use {@link #decodeBase64Standard(byte[])} or {@link #decodeBase64UrlSafe(byte[])} methods respectively. This method skips any unknown or
358+
* not supported bytes.
358359
* </p>
359360
*
360361
* @param base64Data Byte array containing Base64 data.
@@ -367,8 +368,9 @@ public static byte[] decodeBase64(final byte[] base64Data) {
367368
/**
368369
* Decodes a Base64 String into octets.
369370
* <p>
370-
* This method seamlessly handles data encoded in URL-safe or normal mode. For enforcing verification against strict standard Base64 or Base64 URL Safe
371-
* tables, please use {@link #decodeBase64Standard} or {@link #decodeBase64Url} methods respectively. This method skips any unknown or not supported bytes.
371+
* This method seamlessly handles data encoded in URL-safe or normal mode. For enforcing verification against strict standard Base64 or Base64 URL-safe
372+
* tables, please use {@link #decodeBase64Standard(String)} or {@link #decodeBase64UrlSafe(String)} methods respectively. This method skips any unknown or
373+
* not supported bytes.
372374
* </p>
373375
*
374376
* @param base64String String containing Base64 data.
@@ -410,7 +412,7 @@ public static byte[] decodeBase64Standard(final String base64String) {
410412
}
411413

412414
/**
413-
* Decodes URL Safe Base64 data into octets.
415+
* Decodes URL-safe Base64 data into octets.
414416
* <p>
415417
* This implementation is aligned with
416418
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#:~:text=Table%202%3A%20The%20%22URL%20and%20Filename%20safe%22%20Base%2064%20Alphabet">RFC 4648
@@ -421,12 +423,12 @@ public static byte[] decodeBase64Standard(final String base64String) {
421423
* @return New array containing decoded data.
422424
* @since 1.21
423425
*/
424-
public static byte[] decodeBase64Url(final byte[] base64Data) {
426+
public static byte[] decodeBase64UrlSafe(final byte[] base64Data) {
425427
return builder().setDecodeTableFormat(DecodeTableFormat.URL_SAFE).get().decode(base64Data);
426428
}
427429

428430
/**
429-
* Decodes a URL Safe Base64 String into octets.
431+
* Decodes a URL-safe Base64 String into octets.
430432
* <p>
431433
* This implementation is aligned with
432434
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#:~:text=Table%202%3A%20The%20%22URL%20and%20Filename%20safe%22%20Base%2064%20Alphabet">RFC 4648
@@ -437,7 +439,7 @@ public static byte[] decodeBase64Url(final byte[] base64Data) {
437439
* @return New array containing decoded data.
438440
* @since 1.21
439441
*/
440-
public static byte[] decodeBase64Url(final String base64String) {
442+
public static byte[] decodeBase64UrlSafe(final String base64String) {
441443
return builder().setDecodeTableFormat(DecodeTableFormat.URL_SAFE).get().decode(base64String);
442444
}
443445

@@ -593,8 +595,8 @@ public static boolean isArrayByteBase64(final byte[] arrayOctet) {
593595
* Tests whether or not the {@code octet} is in the base 64 alphabet.
594596
* <p>
595597
* This method threats all characters included within standard base64 and base64url encodings as valid base64 characters. This includes the '+' and '/'
596-
* (standard base64), as well as '-' and '_' (URL-safe base64) characters. For enforcing verification against strict standard Base64 or Base64 URL Safe
597-
* tables, please use {@link #isBase64Standard} or {@link #isBase64Url} methods respectively.
598+
* (standard base64), as well as '-' and '_' (URL-safe base64) characters. For enforcing verification against strict standard Base64 or Base64 URL-safe
599+
* tables, please use {@link #isBase64Standard(byte)} or {@link #isBase64Url(byte)} methods respectively.
598600
* </p>
599601
*
600602
* @param octet The value to test.
@@ -609,8 +611,8 @@ public static boolean isBase64(final byte octet) {
609611
* Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the method treats whitespace as valid.
610612
* <p>
611613
* This method treats all characters included within standard base64 and base64url encodings as valid base64 characters. This includes the '+' and '/'
612-
* (standard base64), as well as '-' and '_' (URL-safe base64) characters. For enforcing verification against strict standard Base64 or Base64 URL Safe
613-
* tables, please use {@link #isBase64Standard} or {@link #isBase64Url} methods respectively.
614+
* (standard base64), as well as '-' and '_' (URL-safe base64) characters. For enforcing verification against strict standard Base64 or Base64 URL-safe
615+
* tables, please use {@link #isBase64Standard(byte[])} or {@link #isBase64Url(byte[])} methods respectively.
614616
* </p>
615617
*
616618
* @param arrayOctet byte array to test.
@@ -630,8 +632,8 @@ public static boolean isBase64(final byte[] arrayOctet) {
630632
* Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the method treats whitespace as valid.
631633
* <p>
632634
* This method threats all characters included within standard base64 and base64url encodings as valid base64 characters. This includes the '+' and '/'
633-
* (standard base64), as well as '-' and '_' (URL-safe base64) characters. For enforcing verification against strict standard Base64 or Base64 URL Safe
634-
* tables, please use {@link #isBase64Standard} or {@link #isBase64Url} methods respectively.
635+
* (standard base64), as well as '-' and '_' (URL-safe base64) characters. For enforcing verification against strict standard Base64 or Base64 URL-safe
636+
* tables, please use {@link #isBase64Standard(String)} or {@link #isBase64Url(String)} methods respectively.
635637
* </p>
636638
*
637639
* @param base64 String to test.
@@ -710,15 +712,15 @@ public static boolean isBase64Url(final byte octet) {
710712
}
711713

712714
/**
713-
* Tests a given byte array to see if it contains only valid characters within the URL Safe Base64 alphabet. The method treats whitespace as valid.
715+
* Tests a given byte array to see if it contains only valid characters within the URL-safe Base64 alphabet. The method treats whitespace as valid.
714716
* <p>
715717
* This implementation is aligned with
716718
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#:~:text=Table%202%3A%20The%20%22URL%20and%20Filename%20safe%22%20Base%2064%20Alphabet">RFC 4648
717719
* Table 2: The "URL and Filename safe" Base 64 Alphabet</a>.
718720
* </p>
719721
*
720722
* @param arrayOctet byte array to test.
721-
* @return {@code true} if all bytes are valid characters in the URL Safe Base64 alphabet, {@code false}, otherwise.
723+
* @return {@code true} if all bytes are valid characters in the URL-safe Base64 alphabet, {@code false}, otherwise.
722724
* @since 1.21
723725
*/
724726
public static boolean isBase64Url(final byte[] arrayOctet) {
@@ -731,15 +733,15 @@ public static boolean isBase64Url(final byte[] arrayOctet) {
731733
}
732734

733735
/**
734-
* Tests a given String to see if it contains only valid characters within the URL Safe Base64 alphabet. The method treats whitespace as valid.
736+
* Tests a given String to see if it contains only valid characters within the URL-safe Base64 alphabet. The method treats whitespace as valid.
735737
* <p>
736738
* This implementation is aligned with
737739
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#:~:text=Table%202%3A%20The%20%22URL%20and%20Filename%20safe%22%20Base%2064%20Alphabet">RFC 4648
738740
* Table 2: The "URL and Filename safe" Base 64 Alphabet</a>.
739741
* </p>
740742
*
741743
* @param base64 String to test.
742-
* @return {@code true} if all characters in the String are valid characters in the URL Safe Base64 alphabet or if the String is empty; {@code false},
744+
* @return {@code true} if all characters in the String are valid characters in the URL-safe Base64 alphabet or if the String is empty; {@code false},
743745
* otherwise.
744746
* @since 1.21
745747
*/

src/test/java/org/apache/commons/codec/binary/Base64Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ void testDecodeEncodeStandard(final String encodedText) {
983983
"Zm9vYmF_"
984984
})
985985
void testDecodeEncodeUrl(final String encodedText) {
986-
final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64Url(encodedText));
986+
final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText));
987987
final String encodedText2 = Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8(decodedText));
988988
assertEquals(encodedText, encodedText2);
989989
}
@@ -1006,9 +1006,9 @@ void testDecodeBase64StandardDiffChars() {
10061006

10071007
@Test
10081008
void testDecodeBase64UrlDiffChars() {
1009-
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64Url("Zm9vYmF"));
1010-
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64Url("Zm9vYmF+"));
1011-
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64Url("Zm9vYmF-"));
1009+
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64UrlSafe("Zm9vYmF"));
1010+
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64UrlSafe("Zm9vYmF+"));
1011+
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64UrlSafe("Zm9vYmF-"));
10121012
assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~"));
10131013
}
10141014

0 commit comments

Comments
 (0)