|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.stax2.ri.typed.AsciiValueEncoder
public abstract class AsciiValueEncoder
This base class defines interface used for efficient encoding of typed values, by stream writers. The abstraction is necessary to reduce amount of duplicated code while avoiding significant additional overhead. The idea is that the low-level stream writer backend supplies encoder with the result buffer, while encoder itself knows the data and state. Together these allow for efficient serialization with light coupling.
General contract for encoding is that caller must call things in following sequence:
bufferNeedsFlush(int)
is called once; and
if indicated by return value of true, caller must flush
its buffer so it is completely empty (buffer also must have
size of at at least MIN_CHARS_WITHOUT_FLUSH)
encodeMore(char[], int, int)
methods is to be called
isCompleted()
should be called
to determine if encoding was complete: if it was, there is
nothing more to do.
encodeMore(char[], int, int)
followed
by a call to isCompleted()
and flushing, as long
as necessary to complete encoding.
Main restrictions for use are that value serializations must produce only 7-bit ascii characters, and that the value can be produced incrementally using limited size buffers. This is true for all current value types of the Typed Access API.
Finally, details of how encoders are created and/or reused is outside scope of this public interface. Stax2 reference implementation handles this using an encoder factory that knows construction details.
Field Summary | |
---|---|
protected static int |
MIN_CHARS_WITHOUT_FLUSH
Constant used to determine when caller should flush buffer before calling encode methods. |
Constructor Summary | |
---|---|
protected |
AsciiValueEncoder()
|
Method Summary | |
---|---|
boolean |
bufferNeedsFlush(int freeChars)
Method called by writer to check if it should flush its output buffer (which has specified amount of free space) before encoder can encode more data. |
abstract int |
encodeMore(byte[] buffer,
int ptr,
int end)
|
abstract int |
encodeMore(char[] buffer,
int ptr,
int end)
|
abstract boolean |
isCompleted()
Method that can alternatively be called to determine whether encoder has encoded all data it has. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int MIN_CHARS_WITHOUT_FLUSH
Constructor Detail |
---|
protected AsciiValueEncoder()
Method Detail |
---|
public final boolean bufferNeedsFlush(int freeChars)
freeChars
- Amount of free space (in characters) in
the output buffer
public abstract boolean isCompleted()
encodeMore(char[], int, int)
, to figure out whether buffer flush
is needed (there is more data), or encoding is complete.
public abstract int encodeMore(char[] buffer, int ptr, int end)
bufferNeedsFlush(int)
is appropriately called once before calling this
method)public abstract int encodeMore(byte[] buffer, int ptr, int end)
bufferNeedsFlush(int)
is appropriately called once before calling this
method)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |