piercemar commented on a change in pull request #2874:
URL: https://github.com/apache/netbeans/pull/2874#discussion_r614912287



##########
File path: ide/versioning.util/src/org/netbeans/modules/proxy/Base64Encoder.java
##########
@@ -16,102 +16,54 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.netbeans.modules.proxy;
 
-import java.io.ByteArrayOutputStream;
+import java.util.Base64;
 
 /**
  * Bas64 encode utility class.
  *
  * @author Maros Sandor
+ * @deprecated prefer java.util.Base64 instead
  */
+@Deprecated
 public class Base64Encoder {
 
-    private static final char [] characters = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
-
     private Base64Encoder() {
     }
 
-    public static String encode(byte [] data) {
+    public static String encode(byte[] data) {
         return encode(data, false);
     }
-    
-    public static String encode(byte [] data, boolean useNewlines) {
-        int length = data.length;
-        StringBuffer sb = new StringBuffer(data.length * 3 / 2);
-
-        int end = length - 3;
-        int i = 0;
-        int lineCount = 0;
-
-        while (i <= end) {
-            int d = ((((int) data[i]) & 0xFF) << 16) | ((((int) data[i + 1]) & 
0xFF) << 8) | (((int) data[i + 2]) & 0xFF);
-            sb.append(characters[(d >> 18) & 0x3F]);
-            sb.append(characters[(d >> 12) & 0x3F]);
-            sb.append(characters[(d >> 6) & 0x3F]);
-            sb.append(characters[d & 0x3F]);
-            i += 3;
-            
-            if (useNewlines && lineCount++ >= 14) {
-                lineCount = 0;
-                sb.append(System.getProperty("line.separator"));
-            }
-        }
 
-        if (i == length - 2) {
-            int d = ((((int) data[i]) & 0xFF) << 16) | ((((int) data[i + 1]) & 
0xFF) << 8);
-            sb.append(characters[(d >> 18) & 0x3F]);
-            sb.append(characters[(d >> 12) & 0x3F]);
-            sb.append(characters[(d >> 6) & 0x3F]);
-            sb.append("=");
-        } else if (i == length - 1) {
-            int d = (((int) data[i]) & 0xFF) << 16;
-            sb.append(characters[(d >> 18) & 0x3F]);
-            sb.append(characters[(d >> 12) & 0x3F]);
-            sb.append("==");
+    public static String encode(byte[] data, boolean useNewlines) {
+        final String encoded = Base64.getEncoder().encodeToString(data);
+        if (useNewlines) {
+            return wrapText(encoded, 60, System.getProperty("line.separator"));

Review comment:
       thanks for the hint, would be cleaner indeed




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to