- Direct Known Subclasses:
OutputBuffer
Output enables incremental,
interruptible writing of network protocols and data formats.
Output tokens
Output tokens are modeled as primitive ints, commonly
representing Unicode code points, or raw octets; each Output
implementation specifies the semantic type of its tokens.
Output states
Output is always in one of four states: continue,
full, done, or error. The cont state
indicates that the stream is ready to write a single token; the full
state indicates that the stream is unable to write additional tokens at this
time, but that the stream may logically resume at some point in the future;
and the done state indicates that the stream has terminated, and
that bind will return the output result; and the
error state indicates that the stream has terminated abnormally.
isCont() returns true when in the cont state;
isFull() returns true when in the full state;
isDone() returns true when in the done state; and
isError() returns true when in the error state.
Output results
An Output yields a value of type T, obtained via the
bind() method, representing some implementation defined result of
writing the output. For example, an Output<String> implementation
may–but is not required to–yield a String containing all code points
written to the output.
Non-blocking behavior
Output writers never block. An Output that would
otherwise block writing additional output instead enters the full
state, signaling the output generator to back off producing the output, but
to remain prepared to produce additional output in the future. An
Output enters the done state when it encounters the final enf of
its output, signaling to the output generator to stop producing.
Output settings
An output generator may alter the tokens it produces based on its
Output's settings. Uses include pretty printing and
styling generated output. OutputSettings subclasses can provide
additional parameters understood by specialized output producers.
Cloning
An Output may be cloned to branch the token
stream in an implementation specified manner. Not all Output
implementations support cloning.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Tbind()Returns the implementation-defined result of writing the output.clone()Returns an implementation-defined branch of the token stream.Writes the code points of the developer-readableDebugstring of the givenobject.Writes the code points of the human-readableDisplaystring of the givenobject.static <T> Output<T>done()Returns anOutputin the done state, that binds anullresult.static <T> Output<T>done(OutputSettings settings) Returns anOutputin the done state, with the givensettings.static <T> Output<T>done(T value) Returns anOutputin the done state, that binds the givenvalue.static <T> Output<T>done(T value, OutputSettings settings) Returns anOutputin the done state, that binds the givenvalue, with the givensettings.static <T> Output<T>Returns anOutputin the error state, with the given outputerror.static <T> Output<T>error(Throwable error, OutputSettings settings) Returns anOutputin the error state, with the given outputerrorandsettings.flush()Writes any internally buffered state to the underlying output stream.Returns anOutputequivalent to thisOutput, but whose behavior may be altered by the given out-of-bandcondition.static <T> Output<T>full()Returns anOutputin the full state, that binds anullresult.static <T> Output<T>full(OutputSettings settings) Returns anOutputin the full state, with the givensettings.static <T> Output<T>full(T value) Returns anOutputin the full state, that binds the givenvalue.static <T> Output<T>full(T value, OutputSettings settings) Returns anOutputin the full state, that binds the givenvalue, with the givensettings.abstract booleanisCont()Returnstruewhen the nextwrite(int)will succeed.abstract booleanisDone()Returnstruewhen nowritewill ever again suucced.abstract booleanisError()Returnstruewhen an immediatewritewill fail due to an error with the token stream.abstract booleanisFull()Returnstruewhen an immediatewritewill fail, but writes may succeed at some point in the future.abstract booleanisPart()Returnstrueif this is a partialOutputthat will enter the full state when it is unable to write additional tokens.isPart(boolean isPart) Returns a partialOutputequivalent to thisOutput, ifisPartistrue; returns a finalOutputequivalent to thisOutputifisPartisfalse.abstract OutputSettingssettings()Returns theOutputSettingsused to configure the behavior of output producers that write to thisOutput.settings(OutputSettings settings) Updates thesettingsassociated with thisOutput.trap()Returns the output error.write(int token) Writes a singletokento the stream, if thisOutputis in the cont state.Writes the code points of the givenstring.writeln()Writes the code points of thesettings'line separator.Writes the code points of the givenstring, followed by the code points of thesettings'line separator.
-
Constructor Details
-
Output
public Output()
-
-
Method Details
-
isCont
public abstract boolean isCont() -
isFull
public abstract boolean isFull()Returnstruewhen an immediatewritewill fail, but writes may succeed at some point in the future. i.e. thisOutputis in the full state. -
isDone
public abstract boolean isDone()Returnstruewhen nowritewill ever again suucced. i.e. thisOutputis in the done state. -
isError
public abstract boolean isError()Returnstruewhen an immediatewritewill fail due to an error with the token stream. i.e. thisOutputis in the error state. Whentrue,trap()will return the output error. -
isPart
public abstract boolean isPart()Returnstrueif this is a partialOutputthat will enter the full state when it is unable to write additional tokens. -
isPart
Returns a partialOutputequivalent to thisOutput, ifisPartistrue; returns a finalOutputequivalent to thisOutputifisPartisfalse. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
write
Writes a singletokento the stream, if thisOutputis in the cont state. Returns anOutputin the error state if thisOutputis not in the cont state. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
write
Writes the code points of the givenstring. Assumes this is a UnicodeOutputwith sufficient capacity. Returns anOutputin the error state if thisOutputexits the cont state before the fullstringhas been writtem. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
writeln
Writes the code points of the givenstring, followed by the code points of thesettings'line separator. Assumes this is a UnicodeOutputwith sufficient capacity. Returns anOutputin the error state if thisOutputexits the cont state before the fullstringand line separator has been written. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
writeln
Writes the code points of thesettings'line separator. Assumes this is a UnicodeOutputwith sufficient capacity. Returns anOutputin the error state if thisOutputexits the cont state before the full line separator has been written. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
display
Writes the code points of the human-readableDisplaystring of the givenobject. Assumes this is a UnicodeOutputwith sufficient capacity. Returns anOutputin the error state if thisOutputexits the contt state before the full display string has been written. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
debug
Writes the code points of the developer-readableDebugstring of the givenobject. Assumes this is a UnicodeOutputwith sufficient capacity. Returns anOutputin the error state if thisOutputexits the contt state before the full debug string has been written. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
flush
Writes any internally buffered state to the underlying output stream. -
fork
Returns anOutputequivalent to thisOutput, but whose behavior may be altered by the given out-of-bandcondition. The caller's reference tothisOutputshould be replaced by the returnedOutput. -
bind
Returns the implementation-defined result of writing the output. -
trap
Returns the output error. Only guaranteed to return an error when in the error state.- Throws:
OutputException- if thisOutputis not in the error state.
-
settings
Returns theOutputSettingsused to configure the behavior of output producers that write to thisOutput. -
settings
Updates thesettingsassociated with thisOutput.- Returns:
this
-
clone
Returns an implementation-defined branch of the token stream.- Overrides:
clonein classObject- Throws:
UnsupportedOperationException- if thisOutputcannot be cloned.
-
full
Returns anOutputin the full state, that binds anullresult. -
full
Returns anOutputin the full state, with the givensettings. -
full
Returns anOutputin the full state, that binds the givenvalue. -
full
Returns anOutputin the full state, that binds the givenvalue, with the givensettings. -
done
Returns anOutputin the done state, that binds anullresult. -
done
Returns anOutputin the done state, with the givensettings. -
done
Returns anOutputin the done state, that binds the givenvalue. -
done
Returns anOutputin the done state, that binds the givenvalue, with the givensettings. -
error
Returns anOutputin the error state, with the given outputerror. -
error
Returns anOutputin the error state, with the given outputerrorandsettings.
-