[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-27 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883706247


##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -0,0 +1,164 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.hc.client5.http.utils;
+
+
+import org.apache.hc.core5.annotation.Internal;
+
+import static java.util.Base64.getEncoder;
+import static java.util.Base64.getMimeDecoder;
+
+/**
+ * Provide implementations of the Base64 conversion methods from Commons 
Codec, delegating to the Java Base64
+ * implementation.
+ * 
+ * * Only the features currently used by HttpClient are implemented here 
rather than all the features of Commons Codec
+ * Notes:
+ * 
+ * Commons Codec accepts null inputs, so this is also accepted here. This 
is not done in the Java 8 implementation
+ * Decoding invalid input returns an empty value. The Java 8 
implementation throws an exception, which is caught here
+ * Commons Codec decoders accept both standard and url-safe variants of 
input. As this is not a requirement for
+ * HttpClient, this is NOT implemented here.
+ * 
+ * 
+ * This class is intended as in interim convenience. Any new code should use 
`java.util.Base64` directly.
+ */
+@Internal
+public class Base64 {
+private static final Base64 CODEC = new Base64();
+private static final byte[] EMPTY_BYTES = new byte[0];
+
+/**
+ * Return an instance of the Base64 codec that use the regular Base64 
alphabet
+ * (as opposed to the URL-safe alphabet). Note that unlike the Commons 
Codec version,
+ * thus class will NOT decode characters from URL-safe alphabet.
+ */
+public Base64() {
+}
+
+/**
+ * Creates a Base64 codec used for decoding and encoding in URL-unsafe 
mode.
+ * 
+ * As HttpClient never uses a non-zero length, this feature is not 
implemented here.
+ */
+
+public Base64(final int lineLength) {
+if (lineLength != 0) {

Review Comment:
   The constructor taking an integer is used, but only ever with a length of 0. 
The usage could easily be replaced, but I was going out of my way to minimize 
changes to existing code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-26 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883266643


##
httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestBase64.java:
##
@@ -108,21 +108,6 @@ void decodeUnpadded() {
 checkDecode("AAA");
 }
 
-@Test
-void decodeUrlSafe() {
-final char underscore = '_';
-final char minus = '-';
-
-checkDecode(fourOf(minus));
-checkDecode(fourOf(underscore));
-}
-
-@Test
-void mixedUrlAndRegularEncoded() {
-checkDecode("++__");
-checkDecode("--//");
-}
-

Review Comment:
   Tests have been cleaned up



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-26 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883266409


##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -30,39 +30,41 @@
 
 import org.apache.hc.core5.annotation.Internal;
 
-import java.nio.charset.StandardCharsets;
-
 import static java.util.Base64.getEncoder;
 import static java.util.Base64.getMimeDecoder;
 
 /**
  * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
  * implementation.
  * 
+ * * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded
  * Notes:
  * 
  * commons-codec accepts null inputs, so this is also accepted here. This 
is not done in the Java 8 implementation
- * decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
- * commons-codec decoders accept both standard and url-safe variants of 
input. This needs to be remapped for Java 8, as it
- * will accept either one or the other, but not both. This is likely a 
rarely-needed requirement, but is provided to avoid
- * compatibility surprises.
+ * Decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
+ * commons-codec decoders accept both standard and url-safe variants of 
input. As this is not a requirement for
+ * httpcommons-client, this is NOT implemented here.

Review Comment:
   Done



##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -30,39 +30,41 @@
 
 import org.apache.hc.core5.annotation.Internal;
 
-import java.nio.charset.StandardCharsets;
-
 import static java.util.Base64.getEncoder;
 import static java.util.Base64.getMimeDecoder;
 
 /**
  * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
  * implementation.
  * 
+ * * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded
  * Notes:
  * 
  * commons-codec accepts null inputs, so this is also accepted here. This 
is not done in the Java 8 implementation
- * decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
- * commons-codec decoders accept both standard and url-safe variants of 
input. This needs to be remapped for Java 8, as it
- * will accept either one or the other, but not both. This is likely a 
rarely-needed requirement, but is provided to avoid
- * compatibility surprises.
+ * Decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
+ * commons-codec decoders accept both standard and url-safe variants of 
input. As this is not a requirement for
+ * httpcommons-client, this is NOT implemented here.
  * 
- * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded
+ * 
+ * This class is intended as in interim convenience. Any new code should just 
use `java.util.Base64` directly.
  */
 @Internal
 public class Base64 {
+private static final Base64 CODEC = new Base64();
 private static final byte[] EMPTY_BYTES = new byte[0];
 
 /**
- * Creates a Base64 codec used for decoding (all modes) and encoding in 
URL-unsafe mode.
+ * Return an instance of the Base64 codec that use the regular Base64 
alphabet
+ * (as opposed to the URL-safe alphabet). Note that unlike the 
commons-codec version,
+ * thus class will NOT decode characters from URL-safe alphabet.
  */
 public Base64() {
 }
 
 /**
- * Creates a Base64 codec used for decoding (all modes) and encoding in 
URL-unsafe mode.
+ * Creates a Base64 codec used for decoding and encoding in URL-unsafe 
mode.
  * 
- * As http-client never uses a non-zero length, this feature is not 
implemented here.
+ * As httpcommons-client never uses a non-zero length, this feature is not 
implemented here.

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-26 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883266278


##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -30,39 +30,41 @@
 
 import org.apache.hc.core5.annotation.Internal;
 
-import java.nio.charset.StandardCharsets;
-
 import static java.util.Base64.getEncoder;
 import static java.util.Base64.getMimeDecoder;
 
 /**
  * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
  * implementation.
  * 
+ * * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded

Review Comment:
   Done



##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -30,39 +30,41 @@
 
 import org.apache.hc.core5.annotation.Internal;
 
-import java.nio.charset.StandardCharsets;
-
 import static java.util.Base64.getEncoder;
 import static java.util.Base64.getMimeDecoder;
 
 /**
  * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
  * implementation.
  * 
+ * * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded

Review Comment:
   Done



##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -30,39 +30,41 @@
 
 import org.apache.hc.core5.annotation.Internal;
 
-import java.nio.charset.StandardCharsets;
-
 import static java.util.Base64.getEncoder;
 import static java.util.Base64.getMimeDecoder;
 
 /**
  * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
  * implementation.
  * 
+ * * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded
  * Notes:
  * 
  * commons-codec accepts null inputs, so this is also accepted here. This 
is not done in the Java 8 implementation
- * decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
- * commons-codec decoders accept both standard and url-safe variants of 
input. This needs to be remapped for Java 8, as it
- * will accept either one or the other, but not both. This is likely a 
rarely-needed requirement, but is provided to avoid
- * compatibility surprises.
+ * Decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-26 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883266186


##
httpclient5/pom.xml:
##
@@ -80,6 +80,7 @@
 
   commons-codec
   commons-codec
+  test

Review Comment:
   It's removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-26 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883246952


##
httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestBase64.java:
##
@@ -108,21 +108,6 @@ void decodeUnpadded() {
 checkDecode("AAA");
 }
 
-@Test
-void decodeUrlSafe() {
-final char underscore = '_';
-final char minus = '-';
-
-checkDecode(fourOf(minus));
-checkDecode(fourOf(underscore));
-}
-
-@Test
-void mixedUrlAndRegularEncoded() {
-checkDecode("++__");
-checkDecode("--//");
-}
-

Review Comment:
   Having dropped the special handling of URl-safe encoding, a lot less of this 
is needed. I'm cleaning it up.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-26 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r883246292


##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -0,0 +1,223 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.hc.client5.http.utils;
+
+
+import java.nio.charset.StandardCharsets;
+
+import static java.util.Base64.getEncoder;
+import static java.util.Base64.getMimeDecoder;
+
+/**
+ * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
+ * implementation.
+ * 
+ * Notes:
+ * 
+ * commons-codec accepts null inputs, so this is also accepted here. This 
is not done in the Java 8 implementation
+ * decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
+ * commons-codec decoders accept both standard and url-safe variants of 
input. This needs to be remapped for Java 8, as it
+ * will accept either one or the other, but not both. This is likely a 
rarely-needed requirement, but is provided to avoid
+ * compatibility surprises.
+ * 
+ * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded
+ */
+
+public class Base64 {
+private static final byte[] EMPTY_BYTES = new byte[0];
+
+/**
+ * Creates a Base64 codec used for decoding (all modes) and encoding in 
URL-unsafe mode.
+ */
+public Base64() {
+}
+
+/**
+ * Creates a Base64 codec used for decoding (all modes) and encoding in 
URL-unsafe mode.
+ * 
+ * As http-client never uses a non-zero length, this feature is not 
implemented here.
+ */
+
+public Base64(final int lineLength) {
+if (lineLength != 0) {
+throw new UnsupportedOperationException("Line breaks not 
supported");
+}
+}
+
+/**
+ * Decodes Base64 data into octets.
+ * 
+ * Note: this method seamlessly handles data encoded in URL-safe or 
normal mode.
+ */
+public static byte[] decodeBase64(final byte[] base64) {
+if (null == base64) {
+return null;
+}
+
+return 
decodeOrEmptyBytes(UrlByteRemapper.toStandardUrlEncoding(base64));
+}
+
+/**
+ * Decodes a Base64 String into octets.
+ * 
+ * Note: this method seamlessly handles data encoded in URL-safe or 
normal mode.
+ */
+
+public static byte[] decodeBase64(final String base64) {
+if (null == base64) {
+return null;
+}
+
+//The acceptable Base64 alphabets have the same encodings in ASCII, 
ISO_8859_1, and UTF-8.
+//ISO_8859_1 is used here because it matches the choice in the Java 8 
Base64 implementation, and is
+//in principle a tiny bit faster than the others to convert in 
versions of Java that support "compact strings".
+//Any inputs outside the accepted values will be invalid in any 
encoding.
+
+final byte[] bytes = base64.getBytes(StandardCharsets.ISO_8859_1);
+UrlByteRemapper.replaceUrlSafeBytes(bytes);
+
+return decodeOrEmptyBytes(bytes);
+}
+
+/**
+ * Encodes binary data using the base64 algorithm but does not chunk the 
output.
+ */
+
+public static byte[] encodeBase64(final byte[] bytes) {
+if (null == bytes) {
+return null;
+}
+
+return getEncoder().encode(bytes);
+}
+
+/**
+ * Encodes binary data using the base64 algorithm but does not chunk the 
output.
+ */
+
+public static String encodeBase64String(final byte[] bytes) {
+if (null == bytes) {
+return null;
+}
+
+return getEncoder().encodeToString(bytes);
+}
+
+/**
+ * Encode bytes to their Base64 form, using 

[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-24 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880748866


##
httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java:
##
@@ -0,0 +1,223 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.hc.client5.http.utils;
+
+
+import java.nio.charset.StandardCharsets;
+
+import static java.util.Base64.getEncoder;
+import static java.util.Base64.getMimeDecoder;
+
+/**
+ * Provide implementations of the Base64 conversion methods from 
commons-codec, delegating to  the Java Base64
+ * implementation.
+ * 
+ * Notes:
+ * 
+ * commons-codec accepts null inputs, so this is also accepted here. This 
is not done in the Java 8 implementation
+ * decoding invalid inputs returns an empty value. The Java 8 
implementation throws an exception, which is caught here
+ * commons-codec decoders accept both standard and url-safe variants of 
input. This needs to be remapped for Java 8, as it
+ * will accept either one or the other, but not both. This is likely a 
rarely-needed requirement, but is provided to avoid
+ * compatibility surprises.
+ * 
+ * Only the features currently used by http-client are implemented here 
rather than all the features of commons-coded
+ */
+
+public class Base64 {

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-24 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880745172


##
httpclient5/pom.xml:
##
@@ -80,6 +80,7 @@
 
   commons-codec
   commons-codec
+  test

Review Comment:
   Should be able to. Right now my test iterates over lots of inputs and 
compares what each codec returns. This is likely overkill - I will update the 
tests to use constant expected values for a reasonable number of points.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-24 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880445736


##
httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java:
##
@@ -129,7 +128,7 @@ public byte[] encode(final byte[] bytes) {
 return buffer.toByteArray();
 }
 
-public byte[] decode(final byte[] bytes) throws DecoderException {
+public byte[] decode(final byte[] bytes) throws 
IllegalArgumentException {

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-24 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880445353


##
httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java:
##
@@ -163,13 +162,13 @@ public byte[] decode(final byte[] bytes) throws 
DecoderException {
  *The byte to be converted.
  * @return The numeric value represented by the character in radix 16.
  *
- * @throws DecoderException
+ * @throws IllegalArgumentException
  * Thrown when the byte is not valid per {@link 
Character#digit(char,int)}
  */
-static int digit16(final byte b) throws DecoderException {
+static int digit16(final byte b) throws IllegalArgumentException {
 final int i = Character.digit((char) b, RADIX);
 if (i == -1) {
-throw new DecoderException("Invalid URL encoding: not a valid 
digit (radix " + RADIX + "): " + b);
+throw new IllegalArgumentException("Invalid URL encoding: not a 
valid digit (radix " + RADIX + "): " + b);

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-24 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880444994


##
httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java:
##
@@ -138,7 +137,7 @@ public byte[] decode(final byte[] bytes) throws 
DecoderException {
 final int b = bytes[i];
 if (b == ESCAPE_CHAR) {
 if (i >= bytes.length - 2) {
-throw new DecoderException("Invalid URL encoding: too 
short");
+throw new IllegalArgumentException("Invalid URL 
encoding: too short");

Review Comment:
   That's the original message, but agreed it seems wrong. Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-23 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880038917


##
httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java:
##
@@ -129,7 +128,7 @@ public byte[] encode(final byte[] bytes) {
 return buffer.toByteArray();
 }
 
-public byte[] decode(final byte[] bytes) throws DecoderException {
+public byte[] decode(final byte[] bytes) throws 
IllegalArgumentException {

Review Comment:
   Since this class is package scoped, there won't be any external code 
expecting this exception



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[GitHub] [httpcomponents-client] j3graham commented on a diff in pull request #370: HTTPCLIENT-2218: Use Java 8 Base64 utility

2022-05-23 Thread GitBox


j3graham commented on code in PR #370:
URL: 
https://github.com/apache/httpcomponents-client/pull/370#discussion_r880025041


##
httpclient5-testing/src/main/java/org/apache/hc/client5/testing/auth/BasicAuthTokenExtractor.java:
##
@@ -49,9 +47,9 @@ public String extract(final String challengeResponse) throws 
HttpException {
 final String s = challengeResponse.substring(i + 1).trim();
 try {
 final byte[] credsRaw = 
s.getBytes(StandardCharsets.US_ASCII);
-final BinaryDecoder codec = new Base64();
+final Base64 codec = new Base64();
 return new String(codec.decode(credsRaw), 
StandardCharsets.US_ASCII);
-} catch (final DecoderException ex) {

Review Comment:
   Although `BinaryDecoder.decode` declares this exception, the Base64 
subclasses did not actually ever throw the exception. I've left the handling in 
place as a reminder of how invalid inputs can be handled. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org