public abstract class Codec extends Object
Callers should not make any assumptions about stream buffering, and must close the streams (if appropriate) after encoding/decoding.
Any method may throw CodecException
.
Instances are thread-safe and reentrant.
Modifier and Type | Field and Description |
---|---|
protected static byte[] |
EMPTY_ARRAY |
Constructor and Description |
---|
Codec() |
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(byte[] src)
Convenience method that decodes the passed array.
|
byte[] |
decode(byte[] src,
int off,
int len)
Convenience method that decodes a section of the passed array.
|
abstract void |
decode(InputStream in,
OutputStream out)
Decodes a stream according to the rules of the codec.
|
byte[] |
encode(byte[] src)
Convenience method that encodes the passed array.
|
byte[] |
encode(byte[] src,
int off,
int len)
Convenience method that encodes a section of the passed array.
|
abstract void |
encode(InputStream in,
OutputStream out)
Encodes a stream according to the rules of the codec.
|
protected static int |
nextNonWhitespace(InputStream in)
Returns the next non-whitespace character from the input stream, -1 if at EOF.
|
protected static void |
skipIfSeparator(InputStream in,
byte[] separator)
Checks the content of the stream against the separator, and skips
the separator if they match.
|
protected static InputStream |
wrapIfNeeded(InputStream in,
byte[] separator)
Optionally wraps the passed input stream to allow backtracking with
the passed separator.
|
public abstract void encode(InputStream in, OutputStream out)
public abstract void decode(InputStream in, OutputStream out)
IllegalArgumentException
- if the input stream is not encoded correctly.public byte[] encode(byte[] src)
public byte[] encode(byte[] src, int off, int len)
public byte[] decode(byte[] src)
public byte[] decode(byte[] src, int off, int len)
protected static InputStream wrapIfNeeded(InputStream in, byte[] separator)
protected static void skipIfSeparator(InputStream in, byte[] separator) throws IOException
IOException
protected static int nextNonWhitespace(InputStream in) throws IOException
IOException