com.foxinmy.weixin4j.base64
Class BaseNCodec

java.lang.Object
  extended by com.foxinmy.weixin4j.base64.BaseNCodec
Direct Known Subclasses:
Base64

public abstract class BaseNCodec
extends Object

reference of apache pivot

Abstract superclass for Base-N encoders and decoders.

This class is thread-safe.

Version:
$Id: BaseNCodec.java 1465182 2013-04-06 04:03:12Z ggregory $

Field Summary
static int MIME_CHUNK_SIZE
          MIME chunk size per RFC 2045 section 6.8.
static int PEM_CHUNK_SIZE
          PEM chunk size per RFC 1421 section 4.3.2.4.
 
Method Summary
 byte[] decode(byte[] pArray)
          Decodes a byte[] containing characters in the Base-N alphabet.
 Object decode(Object obj)
          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 obj)
          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.
 long getEncodedLength(byte[] pArray)
          Calculates the amount of space needed to encode the supplied array.
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIME_CHUNK_SIZE

public static final int MIME_CHUNK_SIZE
MIME 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.

See Also:
RFC 2045 section 6.8, Constant Field Values

PEM_CHUNK_SIZE

public static final int PEM_CHUNK_SIZE
PEM 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.

See Also:
RFC 1421 section 4.3.2.4, Constant Field Values
Method Detail

encode

public Object encode(Object obj)
              throws io.netty.handler.codec.EncoderException
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[].

Parameters:
obj - Object to encode
Returns:
An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied.
Throws:
io.netty.handler.codec.EncoderException - if the parameter supplied is not of type byte[]

encodeToString

public String encodeToString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet. Uses UTF8 encoding.

Parameters:
pArray - a byte array containing binary data
Returns:
A String containing only Base-N character data

encodeAsString

public String encodeAsString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet. Uses UTF8 encoding.

Parameters:
pArray - a byte array containing binary data
Returns:
String containing only character data in the appropriate alphabet.

decode

public Object decode(Object obj)
              throws io.netty.handler.codec.DecoderException
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.

Parameters:
obj - Object to decode
Returns:
An object (of type byte[]) containing the binary data which corresponds to the byte[] or String supplied.
Throws:
io.netty.handler.codec.DecoderException - if the parameter supplied is not of type byte[]

decode

public byte[] decode(String pArray)
Decodes a String containing characters in the Base-N alphabet.

Parameters:
pArray - A String containing Base-N character data
Returns:
a byte array containing binary data

decode

public byte[] decode(byte[] pArray)
Decodes a byte[] containing characters in the Base-N alphabet.

Parameters:
pArray - A byte array containing Base-N character data
Returns:
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.

Parameters:
pArray - a byte array containing binary data
Returns:
A byte array containing only the basen alphabetic character data

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.

Parameters:
arrayOctet - byte array to test
allowWSPad - if true, then whitespace and PAD are also allowed
Returns:
true if all bytes are valid characters in the alphabet or if the byte array is empty; false, otherwise

isInAlphabet

public boolean isInAlphabet(String basen)
Tests a given String to see if it contains only valid characters within the alphabet. The method treats whitespace and PAD as valid.

Parameters:
basen - String to test
Returns:
true if all characters in the String are valid characters in the alphabet or if the String is empty; false, otherwise
See Also:
isInAlphabet(byte[], boolean)

getEncodedLength

public long getEncodedLength(byte[] pArray)
Calculates the amount of space needed to encode the supplied array.

Parameters:
pArray - byte[] array which will later be encoded
Returns:
amount of space needed to encoded the supplied array. Returns a long since a max-len array will require > Integer.MAX_VALUE


Copyright © 2014–2017. All rights reserved.