Package org.apache.ws.commons.util
Class Base64
java.lang.Object
org.apache.ws.commons.util.Base64
Performs Base64 encoding and/or decoding. This is an on-the-fly decoder: Unlike,
for example, the commons-codec classes, it doesn't depend on byte arrays. In
other words, it has an extremely low memory profile. This is well suited even
for very large byte streams.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An encoder is an object, which is able to decode char arrays in blocks of four bytes.static class
An exception of this type is thrown, if the decoded character stream contains invalid input.static class
An encoder is an object, which is able to encode byte array in blocks of three bytes.static class
AnOutputStream
, which is writing to the givenBase64.Encoder
.static class
AnBase64.Encoder
, which is writing to a SAX content handler.static class
An exception of this type is thrown by theBase64.SAXEncoder
, if writing to the target handler causes a SAX exception. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
This array is a lookup table that translates unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents.private static final char[]
This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045.static final String
Default line separator: \nstatic final int
Default size for line wrapping. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(char[] pBuffer) Converts the given base64 encoded character buffer into a byte array.static byte[]
decode
(char[] pBuffer, int pOffset, int pLength) Converts the given base64 encoded character buffer into a byte array.static byte[]
Converts the given base64 encoded String into a byte array.static String
encode
(byte[] pBuffer) Converts the given byte array into a base64 encoded character array with the line sizeLINE_SIZE
and the separatorLINE_SEPARATOR
.static String
encode
(byte[] pBuffer, int pOffset, int pLength) Converts the given byte array into a base64 encoded character array.static String
Converts the given byte array into a base64 encoded character array.static Writer
newDecoder
(OutputStream pStream) Returns aWriter
, that decodes its Base64 encoded input and writes it to the givenOutputStream
.static OutputStream
newEncoder
(Writer pWriter) Returns anOutputStream
, that encodes its input in Base64 and writes it to the givenWriter
.static OutputStream
newEncoder
(Writer pWriter, int pLineSize, String pSeparator) Returns anOutputStream
, that encodes its input in Base64 and writes it to the givenWriter
.
-
Field Details
-
LINE_SEPARATOR
Default line separator: \n- See Also:
-
LINE_SIZE
public static final int LINE_SIZEDefault size for line wrapping.- See Also:
-
intToBase64
private static final char[] intToBase64This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045. -
base64ToInt
private static final byte[] base64ToIntThis array is a lookup table that translates unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the array are translated to -1.
-
-
Constructor Details
-
Base64
public Base64()
-
-
Method Details
-
newEncoder
Returns anOutputStream
, that encodes its input in Base64 and writes it to the givenWriter
. If the Base64 stream ends, then the output streamsOutputStream.close()
method must be invoked. Note, that this will not close the targetWriter
!- Parameters:
pWriter
- Target writer.- Returns:
- An output stream, encoding its input in Base64 and writing
the output to the writer
pWriter
.
-
newEncoder
Returns anOutputStream
, that encodes its input in Base64 and writes it to the givenWriter
. If the Base64 stream ends, then the output streamsOutputStream.close()
method must be invoked. Note, that this will not close the targetWriter
!- Parameters:
pWriter
- Target writer.pLineSize
- Size of one line in characters, must be a multiple of four. Zero indicates, that no line wrapping should occur.pSeparator
- Line separator or null, in which case the default valueLINE_SEPARATOR
is used.- Returns:
- An output stream, encoding its input in Base64 and writing
the output to the writer
pWriter
.
-
encode
Converts the given byte array into a base64 encoded character array.- Parameters:
pBuffer
- The buffer being encoded.pOffset
- Offset in buffer, where to begin encoding.pLength
- Number of bytes being encoded.- Returns:
- Character array of encoded bytes.
-
encode
public static String encode(byte[] pBuffer, int pOffset, int pLength, int pLineSize, String pSeparator) Converts the given byte array into a base64 encoded character array.- Parameters:
pBuffer
- The buffer being encoded.pOffset
- Offset in buffer, where to begin encoding.pLength
- Number of bytes being encoded.pLineSize
- Size of one line in characters, must be a multiple of four. Zero indicates, that no line wrapping should occur.pSeparator
- Line separator or null, in which case the default valueLINE_SEPARATOR
is used.- Returns:
- Character array of encoded bytes.
-
encode
Converts the given byte array into a base64 encoded character array with the line sizeLINE_SIZE
and the separatorLINE_SEPARATOR
.- Parameters:
pBuffer
- The buffer being encoded.- Returns:
- Character array of encoded bytes.
-
newDecoder
Returns aWriter
, that decodes its Base64 encoded input and writes it to the givenOutputStream
. Note, that the writersWriter.close()
method will not close the output streampStream
!- Parameters:
pStream
- Target output stream.- Returns:
- An output stream, encoding its input in Base64 and writing
the output to the writer
pWriter
.
-
decode
public static byte[] decode(char[] pBuffer, int pOffset, int pLength) throws Base64.DecodingException Converts the given base64 encoded character buffer into a byte array.- Parameters:
pBuffer
- The character buffer being decoded.pOffset
- Offset of first character being decoded.pLength
- Number of characters being decoded.- Returns:
- Converted byte array
- Throws:
Base64.DecodingException
- The input character stream contained invalid data.
-
decode
Converts the given base64 encoded character buffer into a byte array.- Parameters:
pBuffer
- The character buffer being decoded.- Returns:
- Converted byte array
- Throws:
Base64.DecodingException
- The input character stream contained invalid data.
-
decode
Converts the given base64 encoded String into a byte array.- Parameters:
pBuffer
- The string being decoded.- Returns:
- Converted byte array
- Throws:
Base64.DecodingException
- The input character stream contained invalid data.
-