From a401798e5e8f3142b49858c958bfcb9d4a764ddb Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 04 Sep 2012 16:29:01 +0000
Subject: [PATCH] Fix OPENDJ-369: Consider exposing base 64 encode/decode APIs

---
 opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/ByteString.java |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/ByteString.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/ByteString.java
index 2b92904..ae874c8 100755
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/ByteString.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/ByteString.java
@@ -34,6 +34,8 @@
 import java.util.Arrays;
 import java.util.logging.Level;
 
+import org.forgerock.i18n.LocalizedIllegalArgumentException;
+
 import com.forgerock.opendj.util.StaticUtils;
 
 /**
@@ -140,6 +142,23 @@
     }
 
     /**
+     * Returns a byte string containing the Base64 decoded bytes of the provided
+     * string.
+     *
+     * @param s
+     *            The string to use.
+     * @return The byte string containing the Base64 decoded bytes of the
+     *         provided string.
+     * @throws LocalizedIllegalArgumentException
+     *             If the provided string does not contain valid Base64 encoded
+     *             content.
+     * @see #toBase64String()
+     */
+    public static ByteString valueOfBase64(final String s) {
+        return Base64.decode(s);
+    }
+
+    /**
      * Returns a byte string containing the contents of the provided byte array.
      * <p>
      * This method differs from {@link #wrap(byte[])} in that it defensively
@@ -531,6 +550,13 @@
     /**
      * {@inheritDoc}
      */
+    public String toBase64String() {
+        return Base64.encode(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public byte[] toByteArray() {
         return copyTo(new byte[length]);
     }

--
Gitblit v1.10.0