Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Package Functions | Static Package Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
org.apache.commons.codec.binary.BaseNCodec Class Referenceabstract
Inheritance diagram for org.apache.commons.codec.binary.BaseNCodec:
org.apache.commons.codec.BinaryEncoder org.apache.commons.codec.BinaryDecoder org.apache.commons.codec.Encoder org.apache.commons.codec.Decoder org.apache.commons.codec.binary.Base64

Classes

class  Context
 

Public Member Functions

Object encode (final Object obj) throws EncoderException
 
String encodeToString (final byte[] pArray)
 
String encodeAsString (final byte[] pArray)
 
Object decode (final Object obj) throws DecoderException
 
byte[] decode (final String pArray)
 
byte[] decode (final byte[] pArray)
 
byte[] encode (final byte[] pArray)
 
boolean isInAlphabet (final byte[] arrayOctet, final boolean allowWSPad)
 
boolean isInAlphabet (final String basen)
 
long getEncodedLength (final byte[] pArray)
 
- Public Member Functions inherited from org.apache.commons.codec.BinaryEncoder
byte[] encode (byte[] source) throws EncoderException
 
- Public Member Functions inherited from org.apache.commons.codec.Encoder
Object encode (Object source) throws EncoderException
 
- Public Member Functions inherited from org.apache.commons.codec.BinaryDecoder
byte[] decode (byte[] source) throws DecoderException
 
- Public Member Functions inherited from org.apache.commons.codec.Decoder
Object decode (Object source) throws DecoderException
 

Static Public Attributes

static final int MIME_CHUNK_SIZE = 76
 
static final int PEM_CHUNK_SIZE = 64
 

Protected Member Functions

 BaseNCodec (final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, final int chunkSeparatorLength)
 
int getDefaultBufferSize ()
 
byte[] ensureBufferSize (final int size, final Context context)
 
abstract boolean isInAlphabet (byte value)
 
boolean containsAlphabetOrPad (final byte[] arrayOctet)
 

Static Protected Member Functions

static boolean isWhiteSpace (final byte byteToCheck)
 

Protected Attributes

final byte PAD = PAD_DEFAULT
 
final int lineLength
 

Static Protected Attributes

static final int MASK_8BITS = 0xff
 
static final byte PAD_DEFAULT = '='
 

Package Functions

boolean hasData (final Context context)
 
int available (final Context context)
 
int readResults (final byte[] b, final int bPos, final int bAvail, final Context context)
 
abstract void encode (byte[] pArray, int i, int length, Context context)
 
abstract void decode (byte[] pArray, int i, int length, Context context)
 

Static Package Attributes

static final int EOF = -1
 

Private Member Functions

byte[] resizeBuffer (final Context context)
 

Private Attributes

final int unencodedBlockSize
 
final int encodedBlockSize
 
final int chunkSeparatorLength
 

Static Private Attributes

static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2
 
static final int DEFAULT_BUFFER_SIZE = 8192
 

Detailed Description

Abstract superclass for Base-N encoders and decoders.

This class is thread-safe.

Version
$Id$

Definition at line 34 of file BaseNCodec.java.

Constructor & Destructor Documentation

org.apache.commons.codec.binary.BaseNCodec.BaseNCodec ( final int  unencodedBlockSize,
final int  encodedBlockSize,
final int  lineLength,
final int  chunkSeparatorLength 
)
protected

Note lineLength is rounded down to the nearest multiple of encodedBlockSize If chunkSeparatorLength is zero, then chunking is disabled.

Parameters
unencodedBlockSizethe size of an unencoded block (e.g. Base64 = 3)
encodedBlockSizethe size of an encoded block (e.g. Base64 = 4)
lineLengthif > 0, use chunking with a length lineLength
chunkSeparatorLengththe chunk separator length, if relevant

Definition at line 182 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.chunkSeparatorLength, org.apache.commons.codec.binary.BaseNCodec.encodedBlockSize, and org.apache.commons.codec.binary.BaseNCodec.unencodedBlockSize.

Member Function Documentation

int org.apache.commons.codec.binary.BaseNCodec.available ( final Context  context)
package

Returns the amount of buffered data available for reading.

Parameters
contextthe context to be used
Returns
The amount of buffered data available for reading.

Definition at line 207 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.Context.buffer, org.apache.commons.codec.binary.BaseNCodec.Context.pos, and org.apache.commons.codec.binary.BaseNCodec.Context.readPos.

Referenced by org.apache.commons.codec.binary.BaseNCodec.readResults(), and webiopi.devices.serial.Serial.readString().

boolean org.apache.commons.codec.binary.BaseNCodec.containsAlphabetOrPad ( final byte[]  arrayOctet)
protected

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

Parameters
arrayOctetbyte array to test
Returns
true
if any byte is a valid character in the alphabet or PAD;
false
otherwise

Definition at line 470 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.isInAlphabet().

Referenced by org.apache.commons.codec.binary.Base64.Base64().

Object org.apache.commons.codec.binary.BaseNCodec.decode ( final Object  obj) throws 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
objObject to decode
Returns
An object (of type byte[]) containing the binary data which corresponds to the byte[] or String supplied.
Exceptions
DecoderExceptionif the parameter supplied is not of type byte[]

Definition at line 351 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.BaseNCodec.decode().

byte [] org.apache.commons.codec.binary.BaseNCodec.decode ( final String  pArray)

Decodes a String containing characters in the Base-N alphabet.

Parameters
pArrayA String containing Base-N character data
Returns
a byte array containing binary data

Definition at line 368 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.decode(), and org.apache.commons.codec.binary.StringUtils.getBytesUtf8().

byte [] org.apache.commons.codec.binary.BaseNCodec.decode ( final byte[]  pArray)

Decodes a byte[] containing characters in the Base-N alphabet.

Parameters
pArrayA byte array containing Base-N character data
Returns
a byte array containing binary data

Definition at line 380 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.decode(), org.apache.commons.codec.binary.BaseNCodec.Context.pos, org.apache.commons.codec.binary.BaseNCodec.readResults(), and webiopi.utils.version.result.

abstract void org.apache.commons.codec.binary.BaseNCodec.decode ( byte[]  pArray,
int  i,
int  length,
Context  context 
)
abstractpackage
Object org.apache.commons.codec.binary.BaseNCodec.encode ( final Object  obj) throws 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
objObject to encode
Returns
An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied.
Exceptions
EncoderExceptionif the parameter supplied is not of type byte[]

Definition at line 309 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.BaseNCodec.encode(), org.apache.commons.codec.binary.BaseNCodec.encodeAsString(), and org.apache.commons.codec.binary.BaseNCodec.encodeToString().

byte [] org.apache.commons.codec.binary.BaseNCodec.encode ( final byte[]  pArray)

Encodes a byte[] containing binary data, into a byte[] containing characters in the alphabet.

Parameters
pArraya byte array containing binary data
Returns
A byte array containing only the basen alphabetic character data

Definition at line 400 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.encode(), org.apache.commons.codec.binary.BaseNCodec.Context.pos, org.apache.commons.codec.binary.BaseNCodec.Context.readPos, and org.apache.commons.codec.binary.BaseNCodec.readResults().

abstract void org.apache.commons.codec.binary.BaseNCodec.encode ( byte[]  pArray,
int  i,
int  length,
Context  context 
)
abstractpackage
String org.apache.commons.codec.binary.BaseNCodec.encodeAsString ( final byte[]  pArray)

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

Parameters
pArraya byte array containing binary data
Returns
String containing only character data in the appropriate alphabet.

Definition at line 335 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.encode(), and org.apache.commons.codec.binary.StringUtils.newStringUtf8().

String org.apache.commons.codec.binary.BaseNCodec.encodeToString ( final byte[]  pArray)

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

Parameters
pArraya byte array containing binary data
Returns
A String containing only Base-N character data

Definition at line 324 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.encode(), and org.apache.commons.codec.binary.StringUtils.newStringUtf8().

byte [] org.apache.commons.codec.binary.BaseNCodec.ensureBufferSize ( final int  size,
final Context  context 
)
protected

Ensure that the buffer has room for size bytes

Parameters
sizeminimum spare space required
contextthe context to be used

Definition at line 243 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.Context.buffer, org.apache.commons.codec.binary.BaseNCodec.Context.pos, and org.apache.commons.codec.binary.BaseNCodec.resizeBuffer().

Referenced by org.apache.commons.codec.binary.Base64.decode(), and org.apache.commons.codec.binary.Base64.encode().

int org.apache.commons.codec.binary.BaseNCodec.getDefaultBufferSize ( )
protected

Get the default buffer size. Can be overridden.

Returns
DEFAULT_BUFFER_SIZE

Definition at line 216 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.DEFAULT_BUFFER_SIZE.

Referenced by org.apache.commons.codec.binary.BaseNCodec.resizeBuffer().

long org.apache.commons.codec.binary.BaseNCodec.getEncodedLength ( final byte[]  pArray)

Calculates the amount of space needed to encode the supplied array.

Parameters
pArraybyte[] 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

Definition at line 490 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.chunkSeparatorLength.

Referenced by org.apache.commons.codec.binary.Base64.encodeBase64().

boolean org.apache.commons.codec.binary.BaseNCodec.hasData ( final Context  context)
package

Returns true if this object has buffered data for reading.

Parameters
contextthe context to be used
Returns
true if there is data still available for reading.

Definition at line 197 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.Context.buffer.

abstract boolean org.apache.commons.codec.binary.BaseNCodec.isInAlphabet ( byte  value)
abstractprotected

Returns whether or not the octet is in the current alphabet. Does not allow whitespace or pad.

Parameters
valueThe value to test
Returns
true
if the value is defined in the current alphabet,
false
otherwise.

Referenced by org.apache.commons.codec.binary.BaseNCodec.containsAlphabetOrPad(), and org.apache.commons.codec.binary.BaseNCodec.isInAlphabet().

boolean org.apache.commons.codec.binary.BaseNCodec.isInAlphabet ( final byte[]  arrayOctet,
final 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
arrayOctetbyte array to test
allowWSPadif
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

Definition at line 438 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.isInAlphabet(), and org.apache.commons.codec.binary.BaseNCodec.isWhiteSpace().

boolean org.apache.commons.codec.binary.BaseNCodec.isInAlphabet ( final 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
basenString 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)

Definition at line 457 of file BaseNCodec.java.

References org.apache.commons.codec.binary.StringUtils.getBytesUtf8(), and org.apache.commons.codec.binary.BaseNCodec.isInAlphabet().

static boolean org.apache.commons.codec.binary.BaseNCodec.isWhiteSpace ( final byte  byteToCheck)
staticprotected

Checks if a byte value is whitespace or not. Whitespace is taken to mean: space, tab, CR, LF

Parameters
byteToCheckthe byte to check
Returns
true if byte is whitespace, false otherwise

Definition at line 286 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.Base64.isBase64(), and org.apache.commons.codec.binary.BaseNCodec.isInAlphabet().

int org.apache.commons.codec.binary.BaseNCodec.readResults ( final byte[]  b,
final int  bPos,
final int  bAvail,
final Context  context 
)
package

Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail bytes. Returns how many bytes were actually extracted.

Package protected for access from I/O streams.

Parameters
bbyte[] array to extract the buffered data into.
bPosposition in byte[] array to start extraction at.
bAvailamount of bytes we're allowed to extract. We may extract fewer (if fewer are available).
contextthe context to be used
Returns
The number of bytes successfully extracted into the provided byte[] array.

Definition at line 266 of file BaseNCodec.java.

References org.apache.commons.codec.binary.BaseNCodec.available(), org.apache.commons.codec.binary.BaseNCodec.Context.buffer, org.apache.commons.codec.binary.BaseNCodec.Context.eof, org.apache.commons.codec.binary.BaseNCodec.Context.pos, and org.apache.commons.codec.binary.BaseNCodec.Context.readPos.

Referenced by org.apache.commons.codec.binary.BaseNCodec.decode(), and org.apache.commons.codec.binary.BaseNCodec.encode().

byte [] org.apache.commons.codec.binary.BaseNCodec.resizeBuffer ( final Context  context)
private

Member Data Documentation

final int org.apache.commons.codec.binary.BaseNCodec.chunkSeparatorLength
private

Size of chunk separator. Not used unless lineLength > 0.

Definition at line 172 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.BaseNCodec.BaseNCodec(), and org.apache.commons.codec.binary.BaseNCodec.getEncodedLength().

final int org.apache.commons.codec.binary.BaseNCodec.DEFAULT_BUFFER_RESIZE_FACTOR = 2
staticprivate
final int org.apache.commons.codec.binary.BaseNCodec.DEFAULT_BUFFER_SIZE = 8192
staticprivate

Defines the default buffer size - currently {}

  • must be large enough for at least one encoded block+separator

Definition at line 144 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.BaseNCodec.getDefaultBufferSize().

final int org.apache.commons.codec.binary.BaseNCodec.encodedBlockSize
private

Number of bytes in each full block of encoded data, e.g. 3 for Base64 and 8 for Base32

Definition at line 160 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.BaseNCodec.BaseNCodec().

final int org.apache.commons.codec.binary.BaseNCodec.EOF = -1
staticpackage

EOF

Since
1.7

Definition at line 112 of file BaseNCodec.java.

final int org.apache.commons.codec.binary.BaseNCodec.lineLength
protected

Chunksize 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.

Definition at line 167 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.Base64.Base64(), and org.apache.commons.codec.binary.Base64.encode().

final int org.apache.commons.codec.binary.BaseNCodec.MASK_8BITS = 0xff
staticprotected

Mask used to extract 8 bits, used in decoding bytes

Definition at line 147 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.Base64.decode().

final int org.apache.commons.codec.binary.BaseNCodec.MIME_CHUNK_SIZE = 76
static

MIME chunk size per RFC 2045 section 6.8.

The {} character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.

See also
RFC 2045 section 6.8

Definition at line 124 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.Base64.Base64().

final byte org.apache.commons.codec.binary.BaseNCodec.PAD = PAD_DEFAULT
protected
final byte org.apache.commons.codec.binary.BaseNCodec.PAD_DEFAULT = '='
staticprotected

Byte used to pad output.

Definition at line 152 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.Base64.isBase64().

final int org.apache.commons.codec.binary.BaseNCodec.PEM_CHUNK_SIZE = 64
static

PEM chunk size per RFC 1421 section 4.3.2.4.

The {} 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

Definition at line 136 of file BaseNCodec.java.

final int org.apache.commons.codec.binary.BaseNCodec.unencodedBlockSize
private

Number of bytes in each full block of unencoded data, e.g. 4 for Base64 and 5 for Base32

Definition at line 157 of file BaseNCodec.java.

Referenced by org.apache.commons.codec.binary.BaseNCodec.BaseNCodec().


The documentation for this class was generated from the following file: