it.sauronsoftware.base64
Class Base64

java.lang.Object
  extended by it.sauronsoftware.base64.Base64

public class Base64
extends java.lang.Object

Base64 encoding and decoding utility methods, both for binary and textual informations.

Since:
1.1
Version:
1.3
Author:
Carlo Pelliccia

Constructor Summary
Base64()
           
 
Method Summary
static byte[] decode(byte[] bytes)
           Decodes a binary sequence.
static void decode(java.io.File source, java.io.File target)
           Decodes data from the given source file contents and writes them in the given target file.
static void decode(java.io.InputStream inputStream, java.io.OutputStream outputStream)
           Decodes data from the given input stream and writes them in the given output stream.
static java.lang.String decode(java.lang.String str)
           Decodes the supplied string.
static java.lang.String decode(java.lang.String str, java.lang.String charset)
           Decodes the supplied string.
static byte[] encode(byte[] bytes)
           Encodes a binary sequence.
static byte[] encode(byte[] bytes, int wrapAt)
           Encodes a binary sequence, wrapping every encoded line every wrapAt characters.
static void encode(java.io.File source, java.io.File target)
           Encodes data from the given source file contents and writes them in the given target file.
static void encode(java.io.File source, java.io.File target, int wrapAt)
           Encodes data from the given source file contents and writes them in the given target file, wrapping every encoded line every wrapAt characters.
static void encode(java.io.InputStream inputStream, java.io.OutputStream outputStream)
           Encodes data from the given input stream and writes them in the given output stream.
static void encode(java.io.InputStream inputStream, java.io.OutputStream outputStream, int wrapAt)
           Encodes data from the given input stream and writes them in the given output stream, wrapping every encoded line every wrapAt characters.
static java.lang.String encode(java.lang.String str)
           Encodes a string.
static java.lang.String encode(java.lang.String str, java.lang.String charset)
           Encodes a string.
 
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

encode

public static java.lang.String encode(java.lang.String str)
                               throws java.lang.RuntimeException

Encodes a string.

Before the string is encoded in Base64, it is converted in a binary sequence using the system default charset.

Parameters:
str - The source string.
Returns:
The encoded string.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.

encode

public static java.lang.String encode(java.lang.String str,
                                      java.lang.String charset)
                               throws java.lang.RuntimeException

Encodes a string.

Before the string is encoded in Base64, it is converted in a binary sequence using the supplied charset.

Parameters:
str - The source string
charset - The charset name.
Returns:
The encoded string.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.
Since:
1.2

decode

public static java.lang.String decode(java.lang.String str)
                               throws java.lang.RuntimeException

Decodes the supplied string.

The supplied string is decoded into a binary sequence, and then the sequence is encoded with the system default charset and returned.

Parameters:
str - The encoded string.
Returns:
The decoded string.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.

decode

public static java.lang.String decode(java.lang.String str,
                                      java.lang.String charset)
                               throws java.lang.RuntimeException

Decodes the supplied string.

The supplied string is decoded into a binary sequence, and then the sequence is encoded with the supplied charset and returned.

Parameters:
str - The encoded string.
charset - The charset name.
Returns:
The decoded string.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.
Since:
1.2

encode

public static byte[] encode(byte[] bytes)
                     throws java.lang.RuntimeException

Encodes a binary sequence.

If data are large, i.e. if you are working with large binary files, consider to use a Base64OutputStream instead of loading too much data in memory.

Parameters:
bytes - The source sequence.
Returns:
The encoded sequence.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.
Since:
1.2

encode

public static byte[] encode(byte[] bytes,
                            int wrapAt)
                     throws java.lang.RuntimeException

Encodes a binary sequence, wrapping every encoded line every wrapAt characters. A wrapAt value less than 1 disables wrapping.

If data are large, i.e. if you are working with large binary files, consider to use a Base64OutputStream instead of loading too much data in memory.

Parameters:
bytes - The source sequence.
wrapAt - The max line length for encoded data. If less than 1 no wrap is applied.
Returns:
The encoded sequence.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.
Since:
1.2

decode

public static byte[] decode(byte[] bytes)
                     throws java.lang.RuntimeException

Decodes a binary sequence.

If data are large, i.e. if you are working with large binary files, consider to use a Base64InputStream instead of loading too much data in memory.

Parameters:
bytes - The encoded sequence.
Returns:
The decoded sequence.
Throws:
java.lang.RuntimeException - If an unexpected error occurs.
Since:
1.2

encode

public static void encode(java.io.InputStream inputStream,
                          java.io.OutputStream outputStream)
                   throws java.io.IOException

Encodes data from the given input stream and writes them in the given output stream.

The supplied input stream is read until its end is reached, but it's not closed by this method.

The supplied output stream is nor flushed neither closed by this method.

Parameters:
inputStream - The input stream.
outputStream - The output stream.
Throws:
java.io.IOException - If an I/O error occurs.

encode

public static void encode(java.io.InputStream inputStream,
                          java.io.OutputStream outputStream,
                          int wrapAt)
                   throws java.io.IOException

Encodes data from the given input stream and writes them in the given output stream, wrapping every encoded line every wrapAt characters. A wrapAt value less than 1 disables wrapping.

The supplied input stream is read until its end is reached, but it's not closed by this method.

The supplied output stream is nor flushed neither closed by this method.

Parameters:
inputStream - The input stream from which clear data are read.
outputStream - The output stream in which encoded data are written.
wrapAt - The max line length for encoded data. If less than 1 no wrap is applied.
Throws:
java.io.IOException - If an I/O error occurs.

decode

public static void decode(java.io.InputStream inputStream,
                          java.io.OutputStream outputStream)
                   throws java.io.IOException

Decodes data from the given input stream and writes them in the given output stream.

The supplied input stream is read until its end is reached, but it's not closed by this method.

The supplied output stream is nor flushed neither closed by this method.

Parameters:
inputStream - The input stream from which encoded data are read.
outputStream - The output stream in which decoded data are written.
Throws:
java.io.IOException - If an I/O error occurs.

encode

public static void encode(java.io.File source,
                          java.io.File target,
                          int wrapAt)
                   throws java.io.IOException

Encodes data from the given source file contents and writes them in the given target file, wrapping every encoded line every wrapAt characters. A wrapAt value less than 1 disables wrapping.

Parameters:
source - The source file, from which decoded data are read.
target - The target file, in which encoded data are written.
wrapAt - The max line length for encoded data. If less than 1 no wrap is applied.
Throws:
java.io.IOException - If an I/O error occurs.
Since:
1.3

encode

public static void encode(java.io.File source,
                          java.io.File target)
                   throws java.io.IOException

Encodes data from the given source file contents and writes them in the given target file.

Parameters:
source - The source file, from which decoded data are read.
target - The target file, in which encoded data are written.
Throws:
java.io.IOException - If an I/O error occurs.
Since:
1.3

decode

public static void decode(java.io.File source,
                          java.io.File target)
                   throws java.io.IOException

Decodes data from the given source file contents and writes them in the given target file.

Parameters:
source - The source file, from which encoded data are read.
target - The target file, in which decoded data are written.
Throws:
java.io.IOException - If an I/O error occurs.
Since:
1.3