org.idoox.util
Class Base64

java.lang.Object
  extended byorg.idoox.util.Base64

public class Base64
extends java.lang.Object

This class implements Base64 encoding.

Since:
4.6
Component:
Core

Constructor Summary
Base64()
           
 
Method Summary
static byte[] decode(byte[] base64)
          Decodes Base64 array to binary array.
static byte[] decode(byte[] base64, int baseLength)
          Decodes Base64 array to binary array.
static byte[] decode(java.lang.String encodedString)
          Decodes string of Base64 encoded data into binary data.
static byte[] encode(byte[] binary)
          Encodes binary array to Base64 array.
static byte[] encode(byte[] binary, boolean newLines)
          Encodes binary array to Base64 array.
static byte[] encode(byte[] binary, int length, boolean newLines)
          Encodes binary array to Base64 array.
static byte[] encode(byte[] binary, int off, int length, boolean newLines)
          Encodes binary array to Base64 array.
static java.lang.String encodeToString(byte[] binary)
          Encodes binary data into Base64 String.
static java.lang.String encodeToString(byte[] binary, boolean newLines)
          Encodes binary data into Base64 String.
static java.lang.String encodeToString(byte[] binary, int length, boolean newLines)
          Encodes starting length bytes of binary data into Base64 String.
static boolean isValidBase64Byte(byte b)
          Returns true for all bytes in range 'A' - 'Z', 'a' - 'z', '0' - '9', '+', '/', '='.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base64

public Base64()
Method Detail

isValidBase64Byte

public static final boolean isValidBase64Byte(byte b)
Returns true for all bytes in range 'A' - 'Z', 'a' - 'z', '0' - '9', '+', '/', '='.

Parameters:
b - the byte to be checked.
Returns:
false if the given byte is not a character of the Base64 encoding.

encode

public static byte[] encode(byte[] binary,
                            boolean newLines)
Encodes binary array to Base64 array.

Parameters:
binary - input data to encode
newLines - if set to true, a newLine is inserted after each 19 tripplets
Returns:
encoded Base64 array
Throws:
java.lang.NullPointerException - thrown if binary is null

encode

public static byte[] encode(byte[] binary,
                            int length,
                            boolean newLines)
Encodes binary array to Base64 array.

Parameters:
binary - input data to encode
newLines - if set to true, a newLine is inserted after each 19 tripplets
length - sets length of the array to be encoded
Returns:
encoded Base64 array
Throws:
java.lang.NullPointerException - thrown if binary is null

encode

public static byte[] encode(byte[] binary,
                            int off,
                            int length,
                            boolean newLines)
Encodes binary array to Base64 array.

Parameters:
binary - input data to encode
newLines - if set to true, a newLine is inserted after each 19 tripplets
off - offset in the input binary array where to start
length - sets length of the array to be encoded
Returns:
encoded Base64 array
Throws:
java.lang.NullPointerException - thrown if binary is null

decode

public static byte[] decode(byte[] base64)
Decodes Base64 array to binary array.

Parameters:
base64 - input data to decode
Returns:
decoded binary array
Throws:
java.lang.NullPointerException - thrown if binary is null

decode

public static byte[] decode(byte[] base64,
                            int baseLength)
Decodes Base64 array to binary array.

Parameters:
base64 - input data to decode
baseLength - input data length
Returns:
decoded binary array
Throws:
java.lang.NullPointerException - thrown if binary is null

encode

public static byte[] encode(byte[] binary)
Encodes binary array to Base64 array. Includes newline characters after each 19 tripplets.

Parameters:
binary - input data to encode
Throws:
java.lang.NullPointerException - thrown if binary is null

encodeToString

public static java.lang.String encodeToString(byte[] binary)
Encodes binary data into Base64 String. Output String has newline characters after each 19 tripplets.

Parameters:
binary - binary data
Returns:
String of Base64 encoded binary data
Throws:
java.lang.NullPointerException - if binary is null.

encodeToString

public static java.lang.String encodeToString(byte[] binary,
                                              boolean newLines)
Encodes binary data into Base64 String. If newLines is true then output string has newline characters after each 19 tripplets.

Parameters:
binary - binary data
Returns:
string of Base64 encoded binary data
Throws:
java.lang.NullPointerException - if binary is null.

encodeToString

public static java.lang.String encodeToString(byte[] binary,
                                              int length,
                                              boolean newLines)
Encodes starting length bytes of binary data into Base64 String. If newLines is true then output string has newline characters after each 19 tripplets.

Parameters:
binary - binary data
length - sets length of the binary data array to be encoded
Returns:
string of Base64 encoded binary data
Throws:
java.lang.NullPointerException - if binary is null.

decode

public static byte[] decode(java.lang.String encodedString)
Decodes string of Base64 encoded data into binary data.

Parameters:
encodedString - Base64 string
Returns:
decoded binary data
Throws:
java.lang.NullPointerException - if encodedString is null.