|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.codec.binary.BaseNCodec
public abstract class BaseNCodec
Abstract superclass for Base-N encoders and decoders.
This class is not thread-safe. Each thread should use its own instance.
| Field Summary | |
|---|---|
protected byte[] |
buffer
Buffer for streaming. |
protected int |
currentLinePos
Variable tracks how many characters have been written to the current line. |
protected boolean |
eof
Boolean flag to indicate the EOF has been reached. |
protected int |
lineLength
Chunksize for encoding. |
protected static int |
MASK_8BITS
Mask used to extract 8 bits, used in decoding bytes |
static int |
MIME_CHUNK_SIZE
MIME chunk size per RFC 2045 section 6.8. |
protected int |
modulus
Writes to the buffer only occur after every 3/5 reads when encoding, and every 4/8 reads when decoding. |
protected byte |
PAD
|
protected static byte |
PAD_DEFAULT
Byte used to pad output. |
static int |
PEM_CHUNK_SIZE
PEM chunk size per RFC 1421 section 4.3.2.4. |
protected int |
pos
Position where next character should be written in the buffer. |
| Constructor Summary | |
|---|---|
protected |
BaseNCodec(int unencodedBlockSize,
int encodedBlockSize,
int lineLength,
int chunkSeparatorLength)
Note lineLength is rounded down to the nearest multiple of encodedBlockSize
If chunkSeparatorLength is zero, then chunking is disabled. |
| Method Summary | |
|---|---|
protected boolean |
containsAlphabetOrPad(byte[] arrayOctet)
Tests a given byte array to see if it contains any characters within the alphabet or PAD. |
byte[] |
decode(byte[] pArray)
Decodes a byte[] containing characters in the Base-N alphabet. |
Object |
decode(Object pObject)
Decodes an Object using the Base-N algorithm. |
byte[] |
decode(String pArray)
Decodes a String containing characters in the Base-N alphabet. |
byte[] |
encode(byte[] pArray)
Encodes a byte[] containing binary data, into a byte[] containing characters in the alphabet. |
Object |
encode(Object pObject)
Encodes an Object using the Base-N algorithm. |
String |
encodeAsString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet. |
String |
encodeToString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet. |
protected void |
ensureBufferSize(int size)
Ensure that the buffer has room for size bytes |
protected int |
getDefaultBufferSize()
Get the default buffer size. |
long |
getEncodedLength(byte[] pArray)
Calculates the amount of space needed to encode the supplied array. |
protected abstract boolean |
isInAlphabet(byte value)
Returns whether or not the octet is in the current alphabet. |
boolean |
isInAlphabet(byte[] arrayOctet,
boolean allowWSPad)
Tests a given byte array to see if it contains only valid characters within the alphabet. |
boolean |
isInAlphabet(String basen)
Tests a given String to see if it contains only valid characters within the alphabet. |
protected static boolean |
isWhiteSpace(byte byteToCheck)
Checks if a byte value is whitespace or not. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MIME_CHUNK_SIZE
The 76 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.
public static final int PEM_CHUNK_SIZE
The 64 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.
protected static final int MASK_8BITS
protected static final byte PAD_DEFAULT
protected final byte PAD
protected final int lineLength
protected byte[] buffer
protected int pos
protected boolean eof
protected int currentLinePos
protected int modulus
| Constructor Detail |
|---|
protected BaseNCodec(int unencodedBlockSize,
int encodedBlockSize,
int lineLength,
int chunkSeparatorLength)
lineLength is rounded down to the nearest multiple of encodedBlockSize
If chunkSeparatorLength is zero, then chunking is disabled.
unencodedBlockSize - the size of an unencoded block (e.g. Base64 = 3)encodedBlockSize - the size of an encoded block (e.g. Base64 = 4)lineLength - if > 0, use chunking with a length lineLengthchunkSeparatorLength - the chunk separator length, if relevant| Method Detail |
|---|
protected int getDefaultBufferSize()
DEFAULT_BUFFER_SIZEprotected void ensureBufferSize(int size)
size bytes
size - minimum spare space requiredprotected static boolean isWhiteSpace(byte byteToCheck)
byteToCheck - the byte to check
public Object encode(Object pObject)
throws EncoderException
encode in interface EncoderpObject - Object to encode
EncoderException - if the parameter supplied is not of type byte[]public String encodeToString(byte[] pArray)
pArray - a byte array containing binary data
public Object decode(Object pObject)
throws DecoderException
decode in interface DecoderpObject - Object to decode
DecoderException - if the parameter supplied is not of type byte[]public byte[] decode(String pArray)
pArray - A String containing Base-N character data
public byte[] decode(byte[] pArray)
decode in interface BinaryDecoderpArray - A byte array containing Base-N character data
public byte[] encode(byte[] pArray)
encode in interface BinaryEncoderpArray - a byte array containing binary data
public String encodeAsString(byte[] pArray)
pArray - a byte array containing binary data
protected abstract boolean isInAlphabet(byte value)
octet is in the current alphabet.
Does not allow whitespace or pad.
value - The value to test
true if the value is defined in the current alphabet, false otherwise.
public boolean isInAlphabet(byte[] arrayOctet,
boolean allowWSPad)
arrayOctet - byte array to testallowWSPad - if true, then whitespace and PAD are also allowed
true if all bytes are valid characters in the alphabet or if the byte array is empty;
false, otherwisepublic boolean isInAlphabet(String basen)
basen - String to test
true if all characters in the String are valid characters in the alphabet or if
the String is empty; false, otherwiseisInAlphabet(byte[], boolean)protected boolean containsAlphabetOrPad(byte[] arrayOctet)
arrayOctet - byte array to test
true if any byte is a valid character in the alphabet or PAD; false otherwisepublic long getEncodedLength(byte[] pArray)
pArray - byte[] array which will later be encoded
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||