This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit 0856a13762c2f2a60a081064d37af2ff92c8b6d4
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Apr 15 18:00:34 2024 -0400

    Use final
    
    - Use better APIs
    - Formatting
---
 .../org/apache/commons/codec/binary/Base64.java    |  8 +++---
 .../apache/commons/codec/binary/Base64Test.java    | 31 +++++++++++-----------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/binary/Base64.java 
b/src/main/java/org/apache/commons/codec/binary/Base64.java
index a5383d0f..79b31721 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base64.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base64.java
@@ -485,7 +485,7 @@ public class Base64 extends BaseNCodec {
      *          The manual encodeTable - a byte array of 64 chars
      * @since 1.17.0
      */
-    public Base64(byte[] encodeTable) {
+    public Base64(final byte[] encodeTable) {
         this(0, CHUNK_SEPARATOR, encodeTable, DECODING_POLICY_DEFAULT);
     }
 
@@ -599,7 +599,7 @@ public class Base64 extends BaseNCodec {
      *             Thrown when the {@code lineSeparator} contains Base64 
characters.
      * @since 1.15
      */
-    public Base64(final int lineLength, final byte[] lineSeparator, boolean 
urlSafe,
+    public Base64(final int lineLength, final byte[] lineSeparator, final 
boolean urlSafe,
                   final CodecPolicy decodingPolicy) {
         this(lineLength, lineSeparator, urlSafe ? URL_SAFE_ENCODE_TABLE : 
STANDARD_ENCODE_TABLE, decodingPolicy);
     }
@@ -676,8 +676,8 @@ public class Base64 extends BaseNCodec {
      * @param encodeTable that is used to determine decode lookup table
      * @return decodeTable
      */
-    private byte[] calculateDecodeTable(byte[] encodeTable) {
-        byte[] decodeTable = new byte[DECODING_TABLE_LENGTH];
+    private byte[] calculateDecodeTable(final byte[] encodeTable) {
+        final byte[] decodeTable = new byte[DECODING_TABLE_LENGTH];
         Arrays.fill(decodeTable, (byte) -1);
         for (int i = 0; i < encodeTable.length; i++) {
             decodeTable[encodeTable[i]] = (byte) i;
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java 
b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
index b4c35d76..4b6d3773 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
@@ -419,37 +419,36 @@ public class Base64Test {
     public void testCustomEncodingAlphabet() {
         // created a duplicate of STANDARD_ENCODE_TABLE and replaced two chars 
with
         // custom values not already present in table
-        // A => .   B => -
-        byte[] encodeTable = {
+        // A => . B => -
+        // @formatter:off
+        final byte[] encodeTable = {
                 '.', '-', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 
'M',
                 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
'Z',
                 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 
'm',
                 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 
'z',
                 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
         };
+        // @formatter:on
 
         // two instances: one with default table and one with adjusted 
encoding table
-        Base64 b64 = new Base64();
-        Base64 b64customEncoding = new Base64(encodeTable);
+        final Base64 b64 = new Base64();
+        final Base64 b64customEncoding = new Base64(encodeTable);
 
         final String content = "! Hello World - this ยง$%";
 
-        byte[] encodedBytes = b64.encode(StringUtils.getBytesUtf8(content));
-        String encodedContent = StringUtils.newStringUtf8(encodedBytes);
+        final byte[] encodedBytes = 
b64.encode(StringUtils.getBytesUtf8(content));
+        final String encodedContent = StringUtils.newStringUtf8(encodedBytes);
 
-        byte[] encodedBytesCustom = 
b64customEncoding.encode(StringUtils.getBytesUtf8(content));
-        String encodedContentCustom = 
StringUtils.newStringUtf8(encodedBytesCustom);
+        final byte[] encodedBytesCustom = 
b64customEncoding.encode(StringUtils.getBytesUtf8(content));
+        final String encodedContentCustom = 
StringUtils.newStringUtf8(encodedBytesCustom);
 
-        assertTrue(
-                encodedContent.contains("A") && encodedContent.contains("B"), 
"testing precondition not met - ecodedContent should contain parts of modified 
table");
+        assertTrue(encodedContent.contains("A") && 
encodedContent.contains("B"),
+                "testing precondition not met - ecodedContent should contain 
parts of modified table");
 
-        assertEquals(
-                encodedContent
-                        .replaceAll("A", ".").replaceAll("B", "-") // replace 
alphabet adjustments
-                        .replaceAll("=", "") // remove padding (not default 
alphabet)
+        assertEquals(encodedContent.replace('A', '.').replace('B', '-') // 
replace alphabet adjustments
+                .replace("=", "") // remove padding (not default alphabet)
                 , encodedContentCustom);
 
-
         // try decode encoded content
         final byte[] decode = b64customEncoding.decode(encodedBytesCustom);
         final String decodeString = StringUtils.newStringUtf8(decode);
@@ -459,7 +458,7 @@ public class Base64Test {
 
     @Test
     public void testCustomEncodingAlphabet_illegal() {
-        byte[] encodeTable = {
+        final byte[] encodeTable = {
                 '.', '-', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'
         };
         assertThrows(IllegalArgumentException.class, () -> new 
Base64(encodeTable));

Reply via email to