LDAP Classes
Implements Java LDAP

com.novell.ldap.util
Class Base64

java.lang.Object
  extended bycom.novell.ldap.util.Base64

public class Base64
extends java.lang.Object

The Base64 utility class performs base64 encoding and decoding. The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable. The encoding and decoding algorithms are simple, but the encoded data are consistently only about 33 percent larger than the unencoded data. The base64 encoding algorithm is defined by RFC 2045.


Method Summary
static byte[] decode(char[] encodedChars)
          Decodes the input base64 encoded array of characters.
static byte[] decode(java.lang.String encodedString)
          Decodes the input base64 encoded String.
static byte[] decode(java.lang.StringBuffer encodedSBuf, int start, int end)
          Decodes a base64 encoded StringBuffer.
static java.lang.String encode(byte[] inputBytes)
          Encodes the specified bytes into a base64 array of bytes.
static java.lang.String encode(java.lang.String inputString)
          Encodes the specified String into a base64 encoded String object.
static boolean isLDIFSafe(byte[] bytes)
          Checks if the input byte array contains only safe values, that is, the data does not need to be encoded for use with LDIF.
static boolean isLDIFSafe(java.lang.String str)
          Checks if the input String contains only safe values, that is, the data does not need to be encoded for use with LDIF.
static boolean isValidUTF8(byte[] array, boolean isUCS2Only)
          Determines if an array of bytes contains only valid UTF-8 characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static final java.lang.String encode(java.lang.String inputString)
Encodes the specified String into a base64 encoded String object.

Parameters:
inputString - The String object to be encoded.
Returns:
a String containing the encoded value of the input.

encode

public static final java.lang.String encode(byte[] inputBytes)
Encodes the specified bytes into a base64 array of bytes. Each byte in the return array represents a base64 character.

Parameters:
inputBytes - the byte array to be encoded.
Returns:
a String containing the base64 encoded data

decode

public static final byte[] decode(java.lang.String encodedString)
Decodes the input base64 encoded String. The resulting binary data is returned as an array of bytes.

Parameters:
encodedString - The base64 encoded String object.
Returns:
The decoded byte array.

decode

public static final byte[] decode(char[] encodedChars)
Decodes the input base64 encoded array of characters. The resulting binary data is returned as an array of bytes.

Parameters:
encodedChars - The character array containing the base64 encoded data.
Returns:
A byte array object containing decoded bytes.

decode

public static final byte[] decode(java.lang.StringBuffer encodedSBuf,
                                  int start,
                                  int end)
Decodes a base64 encoded StringBuffer. Decodes all or part of the input base64 encoded StringBuffer, each Character value representing a base64 character. The resulting binary data is returned as an array of bytes.

Parameters:
encodedSBuf - The StringBuffer object that contains base64 encoded data.
start - The start index of the base64 encoded data.
end - The end index + 1 of the base64 encoded data.
Returns:
The decoded byte array

isLDIFSafe

public static final boolean isLDIFSafe(byte[] bytes)
Checks if the input byte array contains only safe values, that is, the data does not need to be encoded for use with LDIF. The rules for checking safety are based on the rules for LDIF (LDAP Data Interchange Format) per RFC 2849. The data does not need to be encoded if all the following are true:

The data cannot start with the following byte values:

         00 (NUL)
         10 (LF)
         13 (CR)
         32 (SPACE)
         58 (:)
         60 (<)
         Any character with value greater than 127
         (Negative for a byte value)

The data cannot contain any of the following byte values:

         00 (NUL)
         10 (LF)
         13 (CR)
         Any character with value greater than 127
         (Negative for a byte value)

The data cannot end with a space.

Parameters:
bytes - the bytes to be checked.
Returns:
true if encoding not required for LDIF

isLDIFSafe

public static final boolean isLDIFSafe(java.lang.String str)
Checks if the input String contains only safe values, that is, the data does not need to be encoded for use with LDIF. The rules for checking safety are based on the rules for LDIF (LDAP Data Interchange Format) per RFC 2849. The data does not need to be encoded if all the following are true:

The data cannot start with the following char values:

         00 (NUL)
         10 (LF)
         13 (CR)
         32 (SPACE)
         58 (:)
         60 (<)
         Any character with value greater than 127

The data cannot contain any of the following char values:

         00 (NUL)
         10 (LF)
         13 (CR)
         Any character with value greater than 127

The data cannot end with a space.

Parameters:
str - the String to be checked.
Returns:
true if encoding not required for LDIF

isValidUTF8

public static boolean isValidUTF8(byte[] array,
                                  boolean isUCS2Only)
Determines if an array of bytes contains only valid UTF-8 characters.

UTF-8 is the standard encoding for LDAP strings. If a value contains data that is not valid UTF-8 then data is lost converting the value to a Java String.

In addition, Java Strings currently use UCS2 (Unicode Code Standard 2-byte characters). UTF-8 can be encoded as USC2 and UCS4 (4-byte characters). Some valid UTF-8 characters cannot be represented as UCS2 characters. To determine if all UTF-8 sequences can be encoded into UCS2 characters (a Java String), specify the isUCS2Only parameter as true.

Parameters:
array - An array of bytes that are to be tested for valid UTF-8 encoding.

isUCS2Only - true if the UTF-8 values must be restricted to fit within UCS2 encoding (2 bytes)
Returns:
true if all values in the byte array are valid UTF-8 sequences. If isUCS2Only is true, the method returns false if a UTF-8 sequence generates any character that cannot be represented as a UCS2 character (Java String)

LDAP Classes
Implements Java LDAP

Copyright © 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000