You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/05/27 12:49:04 UTC

(commons-net) branch master updated (a7f78419 -> 59543cbb)

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

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


    from a7f78419 Fill in Base64Test#testDecodeInteger()
     new 6269338f Internal refactoring
     new 6cefa3e6 Better parameter name
     new 59543cbb Javadoc

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/commons/net/util/Base64.java   | 48 +++++++++++-----------
 .../org/apache/commons/net/util/Base64Test.java    | 16 ++++++--
 2 files changed, 37 insertions(+), 27 deletions(-)


(commons-net) 02/03: Better parameter name

Posted by gg...@apache.org.
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-net.git

commit 6cefa3e627c3570901cbeec3df4d36c59808c520
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon May 27 08:43:27 2024 -0400

    Better parameter name
---
 .../java/org/apache/commons/net/util/Base64.java   | 44 +++++++++++-----------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/Base64.java b/src/main/java/org/apache/commons/net/util/Base64.java
index d997d50c..2364125e 100644
--- a/src/main/java/org/apache/commons/net/util/Base64.java
+++ b/src/main/java/org/apache/commons/net/util/Base64.java
@@ -614,19 +614,19 @@ public class Base64 {
     /**
      * Decodes a byte array containing characters in the Base64 alphabet.
      *
-     * @param pArray A byte array containing Base64 character data
+     * @param source A byte array containing Base64 character data
      * @return a byte array containing binary data; will return {@code null} if provided byte array is {@code null}.
      */
-    public byte[] decode(final byte[] pArray) {
+    public byte[] decode(final byte[] source) {
         reset();
-        if (pArray == null || pArray.length == 0) {
-            return pArray;
+        if (source == null || source.length == 0) {
+            return source;
         }
-        final long len = pArray.length * 3 / 4;
+        final long len = source.length * 3 / 4;
         final byte[] buf = new byte[(int) len];
         setInitialBuffer(buf, 0, buf.length);
-        decode(pArray, 0, pArray.length);
-        decode(pArray, 0, -1); // Notify decoder of EOF.
+        decode(source, 0, source.length);
+        decode(source, 0, -1); // Notify decoder of EOF.
 
         // Would be nice to just return buf (like we sometimes do in the encode
         // logic), but we have no idea what the line-length was (could even be
@@ -715,30 +715,30 @@ public class Base64 {
     /**
      * Decodes a String containing characters in the Base64 alphabet.
      *
-     * @param pArray A String containing Base64 character data, must not be {@code null}
+     * @param source A String containing Base64 character data, must not be {@code null}
      * @return a byte array containing binary data
      * @since 1.4
      */
-    public byte[] decode(final String pArray) {
-        return decode(getBytesUtf8(pArray));
+    public byte[] decode(final String source) {
+        return decode(getBytesUtf8(source));
     }
 
     /**
      * Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet.
      *
-     * @param pArray a byte array containing binary data
+     * @param source a byte array containing binary data
      * @return A byte array containing only Base64 character data
      */
-    public byte[] encode(final byte[] pArray) {
+    public byte[] encode(final byte[] source) {
         reset();
-        if (pArray == null || pArray.length == 0) {
-            return pArray;
+        if (source == null || source.length == 0) {
+            return source;
         }
-        final long len = getEncodeLength(pArray, lineLength, lineSeparator);
+        final long len = getEncodeLength(source, lineLength, lineSeparator);
         byte[] buf = new byte[(int) len];
         setInitialBuffer(buf, 0, buf.length);
-        encode(pArray, 0, pArray.length);
-        encode(pArray, 0, -1); // Notify encoder of EOF.
+        encode(source, 0, source.length);
+        encode(source, 0, -1); // Notify encoder of EOF.
         // Encoder might have resized, even though it was unnecessary.
         if (buffer != buf) {
             readResults(buf, 0, buf.length);
@@ -838,16 +838,16 @@ public class Base64 {
     /**
      * Encodes a byte[] containing binary data, into a String containing characters in the Base64 alphabet.
      *
-     * @param pArray a byte array containing binary data
+     * @param source a byte array containing binary data
      * @return A String containing only Base64 character data
      * @since 1.4
      */
-    public String encodeToString(final byte[] pArray) {
-        return newStringUtf8(encode(pArray));
+    public String encodeToString(final byte[] source) {
+        return newStringUtf8(encode(source));
     }
 
-    private byte[] getBytesUtf8(final String pArray) {
-        return pArray.getBytes(StandardCharsets.UTF_8);
+    private byte[] getBytesUtf8(final String source) {
+        return source.getBytes(StandardCharsets.UTF_8);
     }
 
     int getLineLength() {


(commons-net) 03/03: Javadoc

Posted by gg...@apache.org.
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-net.git

commit 59543cbb3f94f60d3a904e3863d807328f6ed7c4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon May 27 08:48:06 2024 -0400

    Javadoc
---
 src/main/java/org/apache/commons/net/util/Base64.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/Base64.java b/src/main/java/org/apache/commons/net/util/Base64.java
index 2364125e..50d58372 100644
--- a/src/main/java/org/apache/commons/net/util/Base64.java
+++ b/src/main/java/org/apache/commons/net/util/Base64.java
@@ -553,7 +553,7 @@ public class Base64 {
      *
      * @param lineLength    Each line of encoded data will be at most of the given length (rounded down to the nearest multiple of 4).
      *                      If {@code lineLength <= 0}, then the output will not be divided into lines (chunks). Ignored when decoding.
-     * @param lineSeparator Each line of encoded data will end with this sequence of bytes.
+     * @param lineSeparator Each line of encoded data will end with this sequence of bytes. Not used for decoding.
      * @throws IllegalArgumentException Thrown when the provided lineSeparator included some base64 characters.
      * @since 1.4
      */
@@ -575,7 +575,7 @@ public class Base64 {
      *
      * @param lineLength    Each line of encoded data will be at most of the given length (rounded down to the nearest multiple of 4).
      *                      If {@code lineLength <= 0}, then the output will not be divided into lines (chunks). Ignored when decoding.
-     * @param lineSeparator Each line of encoded data will end with this sequence of bytes.
+     * @param lineSeparator Each line of encoded data will end with this sequence of bytes. Not used for decoding.
      * @param urlSafe       Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly
      *                      handles both modes.
      * @throws IllegalArgumentException The provided lineSeparator included some base64 characters. That's not going to work!


(commons-net) 01/03: Internal refactoring

Posted by gg...@apache.org.
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-net.git

commit 6269338f954758afb497ea7243da26d147ddb5fb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon May 27 08:38:15 2024 -0400

    Internal refactoring
---
 .../java/org/apache/commons/net/util/Base64Test.java     | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/commons/net/util/Base64Test.java b/src/test/java/org/apache/commons/net/util/Base64Test.java
index a7242298..24a821f2 100644
--- a/src/test/java/org/apache/commons/net/util/Base64Test.java
+++ b/src/test/java/org/apache/commons/net/util/Base64Test.java
@@ -28,6 +28,8 @@ import static org.junit.Assert.fail;
 
 import java.math.BigInteger;
 import java.nio.charset.StandardCharsets;
+import java.util.Base64.Decoder;
+import java.util.Base64.Encoder;
 
 import org.junit.Ignore;
 import org.junit.Test;
@@ -38,14 +40,22 @@ public class Base64Test {
     private void checkDecoders(final String expected, final byte[] actual) {
         final byte[] decoded = Base64.decodeBase64(actual);
         assertEquals(expected, new String(decoded, StandardCharsets.UTF_8));
-        assertEquals(expected, new String(java.util.Base64.getDecoder().decode(actual), StandardCharsets.UTF_8));
+        assertEquals(expected, new String(getJreDecoder().decode(actual), StandardCharsets.UTF_8));
     }
 
     private void checkDecoders(final String expected, final String actual) {
         final byte[] decoded = Base64.decodeBase64(actual);
         assertEquals(expected, new String(decoded));
         assertEquals(expected, new String(decoded, StandardCharsets.UTF_8));
-        assertEquals(expected, new String(java.util.Base64.getDecoder().decode(actual), StandardCharsets.UTF_8));
+        assertEquals(expected, new String(getJreDecoder().decode(actual), StandardCharsets.UTF_8));
+    }
+
+    private Decoder getJreDecoder() {
+        return java.util.Base64.getDecoder();
+    }
+
+    private Encoder getJreEncoder() {
+        return java.util.Base64.getEncoder();
     }
 
     @Test
@@ -122,7 +132,7 @@ public class Base64Test {
     }
 
     private void testDecodeInteger(final BigInteger bi) {
-        assertEquals(bi, Base64.decodeInteger(java.util.Base64.getEncoder().encode(bi.toByteArray())));
+        assertEquals(bi, Base64.decodeInteger(getJreEncoder().encode(bi.toByteArray())));
     }
 
     @Test