public abstract class CharacterEncoder extends Object
[Buffer Prefix]
[Line Prefix][encoded data atoms][Line Suffix]
[Buffer Suffix]
In the CharacterEncoder and CharacterDecoder classes, one complete
chunk of data is referred to as a buffer. Encoded buffers
are all text, and decoded buffers (sometimes just referred to as
buffers) are binary octets.
To create a custom encoder, you must, at a minimum, override three
abstract methods in this class.
| Modifier and Type | Field and Description |
|---|---|
protected PrintStream |
pStream
Stream that understands "printing"
|
| Constructor and Description |
|---|
CharacterEncoder() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract int |
bytesPerAtom()
Return the number of bytes per atom of encoding
|
protected abstract int |
bytesPerLine()
Return the number of bytes that can be encoded per line
|
String |
encode(byte[] aBuffer)
A 'streamless' version of encode that simply takes a buffer of
bytes and returns a string containing the encoded buffer.
|
void |
encode(byte[] aBuffer,
OutputStream aStream)
Encode the buffer in aBuffer and write the encoded
result to the OutputStream aStream.
|
void |
encode(InputStream inStream,
OutputStream outStream)
Encode bytes from the input stream, and write them as text characters
to the output stream.
|
protected abstract void |
encodeAtom(OutputStream aStream,
byte[] someBytes,
int anOffset,
int aLength)
Encode one "atom" of information into characters.
|
String |
encodeBuffer(byte[] aBuffer)
A 'streamless' version of encode that simply takes a buffer of
bytes and returns a string containing the encoded buffer.
|
void |
encodeBuffer(byte[] aBuffer,
OutputStream aStream)
Encode the buffer in aBuffer and write the encoded
result to the OutputStream aStream.
|
void |
encodeBuffer(InputStream inStream,
OutputStream outStream)
Encode bytes from the input stream, and write them as text characters
to the output stream.
|
protected void |
encodeBufferPrefix(OutputStream aStream)
Encode the prefix for the entire buffer.
|
protected void |
encodeBufferSuffix(OutputStream aStream)
Encode the suffix for the entire buffer.
|
protected void |
encodeLinePrefix(OutputStream aStream,
int aLength)
Encode the prefix that starts every output line.
|
protected void |
encodeLineSuffix(OutputStream aStream)
Encode the suffix that ends every output line.
|
protected int |
readFully(InputStream in,
byte[] buffer)
This method works around the bizarre semantics of BufferedInputStream's
read method.
|
protected PrintStream pStream
protected abstract int bytesPerAtom()
protected abstract int bytesPerLine()
protected void encodeBufferPrefix(OutputStream aStream) throws IOException
IOExceptionprotected void encodeBufferSuffix(OutputStream aStream) throws IOException
IOExceptionprotected void encodeLinePrefix(OutputStream aStream, int aLength) throws IOException
IOExceptionprotected void encodeLineSuffix(OutputStream aStream) throws IOException
IOExceptionprotected abstract void encodeAtom(OutputStream aStream, byte[] someBytes, int anOffset, int aLength) throws IOException
IOExceptionprotected int readFully(InputStream in, byte[] buffer) throws IOException
IOExceptionpublic void encode(InputStream inStream, OutputStream outStream) throws IOException
IOExceptionpublic void encode(byte[] aBuffer,
OutputStream aStream)
throws IOException
IOExceptionpublic String encode(byte[] aBuffer)
public void encodeBuffer(InputStream inStream, OutputStream outStream) throws IOException
IOExceptionpublic void encodeBuffer(byte[] aBuffer,
OutputStream aStream)
throws IOException
IOExceptionpublic String encodeBuffer(byte[] aBuffer) throws UnsupportedEncodingException
UnsupportedEncodingExceptionCopyright © 2016–2018. All rights reserved.