Class Base64
- java.lang.Object
-
- org.glassfish.jersey.oauth1.signature.Base64
-
public class Base64 extends java.lang.Object
Base64 encoding util class.
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]
ALPHABET
private static int[]
valueDecoding
-
Constructor Summary
Constructors Constructor Description Base64()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
decode(java.lang.String encoded)
Converts a Base64 encoded string to a byte array.static byte[]
decode(java.lang.String encoded, int offset, int length)
Converts an embedded Base64 encoded string to a byte array.private static void
decodeQuantum(char in1, char in2, char in3, char in4, byte[] out, int outOffset)
Decode 4 Base64 chars as 1, 2, or 3 bytes of data.static java.lang.String
encode(byte[] data)
Converts a byte array into a Base64 encoded string.static java.lang.String
encode(byte[] data, int offset, int length)
Converts a byte array into a Base64 encoded string.private static void
encodeQuantum(byte[] in, int inOffset, int len, char[] out, int outOffset)
Encodes 1, 2, or 3 bytes of data as 4 Base64 chars.
-
-
-
Method Detail
-
encode
public static java.lang.String encode(byte[] data)
Converts a byte array into a Base64 encoded string.- Parameters:
data
- bytes to encode.- Returns:
- base64 encoding of data; 4 chars for every 3 bytes.
-
encode
public static java.lang.String encode(byte[] data, int offset, int length)
Converts a byte array into a Base64 encoded string.- Parameters:
data
- bytes to encode.offset
- which byte to start at.length
- how many bytes to encode; padding will be added if needed.- Returns:
- base64 encoding of data; 4 chars for every 3 bytes.
-
encodeQuantum
private static void encodeQuantum(byte[] in, int inOffset, int len, char[] out, int outOffset)
Encodes 1, 2, or 3 bytes of data as 4 Base64 chars.- Parameters:
in
- buffer of bytes to encode.inOffset
- where the first byte to encode is.len
- how many bytes to encode.out
- buffer to put the output in.outOffset
- where in the output buffer to put the chars.
-
decode
public static byte[] decode(java.lang.String encoded) throws java.io.IOException
Converts a Base64 encoded string to a byte array.- Parameters:
encoded
- Base64 encoded data.- Returns:
- decode binary data; 3 bytes for every 4 chars - minus padding.
- Throws:
java.io.IOException
- if an I/O error occurs reading the data.
-
decode
public static byte[] decode(java.lang.String encoded, int offset, int length) throws java.io.IOException
Converts an embedded Base64 encoded string to a byte array.- Parameters:
encoded
- a String with Base64 data embedded in it.offset
- which char of the String to start at.length
- how many chars to decode; must be a multiple of 4.- Returns:
- decode binary data; 3 bytes for every 4 chars - minus padding.
- Throws:
java.io.IOException
- if an I/O error occurs reading the data.
-
decodeQuantum
private static void decodeQuantum(char in1, char in2, char in3, char in4, byte[] out, int outOffset) throws java.io.IOException
Decode 4 Base64 chars as 1, 2, or 3 bytes of data.- Parameters:
in1
- first char of quantum to decode.in2
- second char of quantum to decode.in3
- third char of quantum to decode.in4
- forth char of quantum to decode.out
- buffer to put the output in.outOffset
- where in the output buffer to put the bytes.- Throws:
java.io.IOException
-
-