public abstract class BaseNCodec extends Object implements BinaryCodec
This class is thread-safe.
| 限定符和类型 | 类和说明 |
|---|---|
protected static class |
BaseNCodec.Context
Holds thread context so classes can be thread-safe.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static byte[] |
CHUNK_SEPARATOR
Chunk separator per RFC 2045 section 2.1.
|
protected static CodecPolicy |
DECODING_POLICY_DEFAULT |
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 byte |
pad |
protected byte |
PAD
已过时。
Use
pad. Will be removed in 2.0. |
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 |
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. |
protected |
BaseNCodec(int unencodedBlockSize,
int encodedBlockSize,
int lineLength,
int chunkSeparatorLength,
byte pad)
Note
lineLength is rounded down to the nearest multiple of encodedBlockSize
If chunkSeparatorLength is zero, then chunking is disabled. |
protected |
BaseNCodec(int unencodedBlockSize,
int encodedBlockSize,
int lineLength,
int chunkSeparatorLength,
byte pad,
CodecPolicy decodingPolicy)
Note
lineLength is rounded down to the nearest multiple of encodedBlockSize
If chunkSeparatorLength is zero, then chunking is disabled. |
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
protected abstract void |
decode(byte[] pArray,
int i,
int length,
BaseNCodec.Context context) |
byte[] |
decode(String pArray)
Decodes a String containing characters in the Base-N alphabet.
|
Object |
decodeObject(Object obj)
Decodes an Object using the Base-N algorithm.
|
byte[] |
encode(byte[] pArray)
Encodes a byte[] containing binary data, into a byte[] containing characters in the alphabet.
|
byte[] |
encode(byte[] pArray,
int offset,
int length)
Encodes a byte[] containing binary data, into a byte[] containing
characters in the alphabet.
|
protected abstract void |
encode(byte[] pArray,
int i,
int length,
BaseNCodec.Context context) |
String |
encodeAsString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet.
|
Object |
encodeObject(Object obj)
Encodes an Object using the Base-N algorithm.
|
String |
encodeToString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet.
|
protected byte[] |
ensureBufferSize(int size,
BaseNCodec.Context context)
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.
|
boolean |
isStrictDecoding() |
protected static boolean |
isWhiteSpace(byte byteToCheck)
Checks if a byte value is whitespace or not.
|
protected static final CodecPolicy DECODING_POLICY_DEFAULT
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
public static final byte[] CHUNK_SEPARATOR
public static final byte PAD_DEFAULT
protected final byte pad
protected final int lineLength
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 relevantprotected BaseNCodec(int unencodedBlockSize,
int encodedBlockSize,
int lineLength,
int chunkSeparatorLength,
byte pad)
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 relevantpad - byte used as padding byte.protected BaseNCodec(int unencodedBlockSize,
int encodedBlockSize,
int lineLength,
int chunkSeparatorLength,
byte pad,
CodecPolicy decodingPolicy)
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 relevantpad - byte used as padding byte.protected int getDefaultBufferSize()
protected byte[] ensureBufferSize(int size,
BaseNCodec.Context context)
size bytessize - minimum spare space requiredcontext - the context to be usedprotected static boolean isWhiteSpace(byte byteToCheck)
byteToCheck - the byte to checkpublic Object encodeObject(Object obj) throws CodecException
obj - Object to encodeCodecException - if the parameter supplied is not of type byte[]public String encodeToString(byte[] pArray)
pArray - a byte array containing binary datapublic String encodeAsString(byte[] pArray)
pArray - a byte array containing binary data
This is a duplicate of encodeToString(byte[]); it was merged during refactoring.
public Object decodeObject(Object obj) throws CodecException
obj - Object to decodeCodecException - if the parameter supplied is not of type byte[]public byte[] decode(String pArray)
pArray - A String containing Base-N character datapublic byte[] decode(byte[] pArray)
decode 在接口中 BinaryCodecdecode 在接口中 BinaryDecoderdecode 在接口中 Decoder<byte[],byte[]>decode 在接口中 ICodec<byte[]>pArray - A byte array containing Base-N character datapublic byte[] encode(byte[] pArray)
encode 在接口中 BinaryCodecencode 在接口中 BinaryEncoderencode 在接口中 Encoder<byte[],byte[]>encode 在接口中 ICodec<byte[]>pArray - a byte array containing binary datapublic byte[] encode(byte[] pArray,
int offset,
int length)
pArray - a byte array containing binary dataoffset - initial offset of the subarray.length - length of the subarray.protected abstract void encode(byte[] pArray,
int i,
int length,
BaseNCodec.Context context)
protected abstract void decode(byte[] pArray,
int i,
int length,
BaseNCodec.Context context)
protected abstract boolean isInAlphabet(byte value)
octet is in the current alphabet.
Does not allow whitespace or pad.value - The value to testtrue 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 allowedtrue 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 testtrue 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)
Intended for use in checking line-ending arrays
arrayOctet - byte array to testtrue 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 encodedpublic boolean isStrictDecoding()
Copyright © 2022. All rights reserved.