public abstract class Coder
extends java.lang.Object
An abstract class that represents an encoding and decoding function, suitable for operations such as encryption and decryption, or compression and decompression.
A Coder object consists of two operations: An encoding operation, which transforms byte sequences into other byte sequences, and a corresponding decoding operation, which is the inverse of the encoding operation.
A Coder has a block size, which is the smallest length of a sequence which can be encoded or decoded. The length of any data which is input to the coder for encoding or decoding must be a multiple of the block size.
This is an abstract class. The following methods need to be implemented in a subclass:
algName -- Returns the algorithm name.blockSize -- Returns the block size.encodeOp -- Encodes a single block of data.decodeOp -- Decodes a single block of data.| Modifier | Constructor and Description |
|---|---|
protected |
Coder()
Standard constructor.
|
| Modifier and Type | Method and Description |
|---|---|
abstract java.lang.String |
algName()
Returns the name of the algorithm which this coder implements.
|
byte[] |
decode(byte[] bytes)
Decodes an entire array of bytes.
|
byte[] |
decode(byte[] bytes, int offset, int length)
Decode an array of bytes, with the specified offset and number of bytes.
|
abstract byte[] |
decodeOp(byte[] bytes)
Decodes an array whose length is exactly equal to the block size.
|
byte[] |
encode(byte[] bytes)
Encode an entire array of bytes.
|
byte[] |
encode(byte[] bytes, int offset, int length)
Encode array of bytes, with the specified offset and number of bytes.
|
abstract byte[] |
encodeOp(byte[] bytes)
Encode an array which is exactly blockSize length.
|
abstract int |
getBlockSize()
Returns the block size of the coder.
|
public abstract int getBlockSize()
public byte[] encode(byte[] bytes,
int offset,
int length)
throws CoderException
bytes - The bytes to be encoded.offset - The index of the start of data.length - The length of the data.CoderException - If coder not initialized, block size incorrect, etc.
public byte[] encode(byte[] bytes)
throws CoderException
bytes - The bytes to be encoded.CoderException - If coder not initialized, block size incorrect, etc.
public abstract byte[] encodeOp(byte[] bytes)
throws CoderException
CoderException - Thrown if blockSize is wrong.
public byte[] decode(byte[] bytes,
int offset,
int length)
throws CoderException
bytes - The bytes to be encoded.offset - The index of the start of data.length - The length of the data.CoderException - If coder not initialized, block size incorrect, etc.
public byte[] decode(byte[] bytes)
throws CoderException
bytes - The data to be decoded.CoderException - If coder not initialized, data is not a multiple of the block size, etc.
public abstract byte[] decodeOp(byte[] bytes)
throws CoderException
bytes - The data to be decoded.CoderException - If blockSize is wrong.public abstract java.lang.String algName()