类 BaseNCodec
java.lang.Object
com.icetech.sdk.util.BaseNCodec
- 直接已知子类:
Base64Util
Abstract superclass for Base-N encoders and decoders.
This class is thread-safe.
- 版本:
- $Id: BaseNCodec.java 1634404 2014-10-26 23:06:10Z ggregory $
-
字段概要
字段修饰符和类型字段说明protected final intChunksize for encoding.protected static final intMask used to extract 8 bits, used in decoding bytesstatic final intMIME chunk size per RFC 2045 section 6.8.protected final byteprotected final byte已过时。protected static final byteByte used to pad output.static final intPEM chunk size per RFC 1421 section 4.3.2.4.static Charset -
构造器概要
构造器限定符构造器说明protectedBaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength) NotelineLengthis rounded down to the nearest multiple ofencodedBlockSizeIfchunkSeparatorLengthis zero, then chunking is disabled.protectedBaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength, byte pad) NotelineLengthis rounded down to the nearest multiple ofencodedBlockSizeIfchunkSeparatorLengthis zero, then chunking is disabled. -
方法概要
修饰符和类型方法说明protected booleancontainsAlphabetOrPad(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.Decodes an Object using the Base-N algorithm.byte[]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.Encodes an Object using the Base-N algorithm.encodeAsString(byte[] pArray) Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet.encodeToString(byte[] pArray) Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet.protected byte[]ensureBufferSize(int size, com.icetech.sdk.util.BaseNCodec.Context context) Ensure that the buffer has room forsizebytesstatic byte[]getBytesUtf8(String string) protected intGet the default buffer size.longgetEncodedLength(byte[] pArray) Calculates the amount of space needed to encode the supplied array.protected abstract booleanisInAlphabet(byte value) Returns whether or not theoctetis in the current alphabet.booleanisInAlphabet(byte[] arrayOctet, boolean allowWSPad) Tests a given byte array to see if it contains only valid characters within the alphabet.booleanisInAlphabet(String basen) Tests a given String to see if it contains only valid characters within the alphabet.protected static booleanisWhiteSpace(byte byteToCheck) Checks if a byte value is whitespace or not.static StringnewStringUtf8(byte[] bytes)
-
字段详细资料
-
MIME_CHUNK_SIZE
public static final int MIME_CHUNK_SIZEMIME chunk size per RFC 2045 section 6.8.The 76 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.
- 另请参阅:
-
PEM_CHUNK_SIZE
public static final int PEM_CHUNK_SIZEPEM chunk size per RFC 1421 section 4.3.2.4.The 64 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.
- 另请参阅:
-
MASK_8BITS
protected static final int MASK_8BITSMask used to extract 8 bits, used in decoding bytes- 另请参阅:
-
PAD_DEFAULT
protected static final byte PAD_DEFAULTByte used to pad output.- 另请参阅:
-
PAD
已过时。Usepad. Will be removed in 2.0.- 另请参阅:
-
pad
protected final byte pad -
lineLength
protected final int lineLengthChunksize for encoding. Not used when decoding. A value of zero or less implies no chunking of the encoded data. Rounded down to nearest multiple of encodedBlockSize. -
UTF8
-
-
构造器详细资料
-
BaseNCodec
protected BaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength) NotelineLengthis rounded down to the nearest multiple ofencodedBlockSizeIfchunkSeparatorLengthis 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 lengthlineLengthchunkSeparatorLength- the chunk separator length, if relevant
-
BaseNCodec
protected BaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength, byte pad) NotelineLengthis rounded down to the nearest multiple ofencodedBlockSizeIfchunkSeparatorLengthis 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 lengthlineLengthchunkSeparatorLength- the chunk separator length, if relevantpad- byte used as padding byte.
-
-
方法详细资料
-
getDefaultBufferSize
protected int getDefaultBufferSize()Get the default buffer size. Can be overridden.- 返回:
DEFAULT_BUFFER_SIZE
-
ensureBufferSize
protected byte[] ensureBufferSize(int size, com.icetech.sdk.util.BaseNCodec.Context context) Ensure that the buffer has room forsizebytes- 参数:
size- minimum spare space requiredcontext- the context to be used- 返回:
- the buffer
-
isWhiteSpace
protected static boolean isWhiteSpace(byte byteToCheck) Checks if a byte value is whitespace or not. Whitespace is taken to mean: space, tab, CR, LF- 参数:
byteToCheck- the byte to check- 返回:
- true if byte is whitespace, false otherwise
-
encode
Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of the Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].- 参数:
obj- Object to encode- 返回:
- An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied.
- 抛出:
Exception- if the parameter supplied is not of type byte[]
-
encodeToString
Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet. Uses UTF8 encoding.- 参数:
pArray- a byte array containing binary data- 返回:
- A String containing only Base-N character data
-
encodeAsString
Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet. Uses UTF8 encoding.- 参数:
pArray- a byte array containing binary data- 返回:
- String containing only character data in the appropriate alphabet.
-
decode
Decodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of the Decoder interface, and will throw a DecoderException if the supplied object is not of type byte[] or String.- 参数:
obj- Object to decode- 返回:
- An object (of type byte[]) containing the binary data which corresponds to the byte[] or String supplied.
- 抛出:
Exception- if the parameter supplied is not of type byte[]
-
decode
Decodes a String containing characters in the Base-N alphabet.- 参数:
pArray- A String containing Base-N character data- 返回:
- a byte array containing binary data
-
decode
public byte[] decode(byte[] pArray) Decodes a byte[] containing characters in the Base-N alphabet.- 参数:
pArray- A byte array containing Base-N character data- 返回:
- a byte array containing binary data
-
encode
public byte[] encode(byte[] pArray) Encodes a byte[] containing binary data, into a byte[] containing characters in the alphabet.- 参数:
pArray- a byte array containing binary data- 返回:
- A byte array containing only the basen alphabetic character data
-
isInAlphabet
protected abstract boolean isInAlphabet(byte value) Returns whether or not theoctetis in the current alphabet. Does not allow whitespace or pad.- 参数:
value- The value to test- 返回:
trueif the value is defined in the current alphabet,falseotherwise.
-
isInAlphabet
public boolean isInAlphabet(byte[] arrayOctet, boolean allowWSPad) Tests a given byte array to see if it contains only valid characters within the alphabet. The method optionally treats whitespace and pad as valid.- 参数:
arrayOctet- byte array to testallowWSPad- iftrue, then whitespace and PAD are also allowed- 返回:
trueif all bytes are valid characters in the alphabet or if the byte array is empty;false, otherwise
-
isInAlphabet
Tests a given String to see if it contains only valid characters within the alphabet. The method treats whitespace and PAD as valid.- 参数:
basen- String to test- 返回:
trueif all characters in the String are valid characters in the alphabet or if the String is empty;false, otherwise- 另请参阅:
-
containsAlphabetOrPad
protected boolean containsAlphabetOrPad(byte[] arrayOctet) Tests a given byte array to see if it contains any characters within the alphabet or PAD. Intended for use in checking line-ending arrays- 参数:
arrayOctet- byte array to test- 返回:
trueif any byte is a valid character in the alphabet or PAD;falseotherwise
-
getEncodedLength
public long getEncodedLength(byte[] pArray) Calculates the amount of space needed to encode the supplied array.- 参数:
pArray- byte[] array which will later be encoded- 返回:
- amount of space needed to encoded the supplied array. Returns a long since a max-len array will require > Integer.MAX_VALUE
-
newStringUtf8
-
getBytesUtf8
-
pad.