- Direct Known Subclasses:
InputBuffer
Input enable incremental, interruptible parsing of network protocols
and data formats.
Input tokens
Input tokens are modeled as primitive ints, commonly representing
Unicode code points, or raw octets; each Input implementation
specifies the semantic type of its tokens. The head() method
peeks at the current lookahead token, without consuming it, and the step() method advances the input to the next token.
Input states
Input is always in one of four states: continue,
empty, done, or error. The cont state
indicates that a lookahead token is immediately available; the empty
state indicates that no additional tokens are available at this time, but
that the stream may logically resume in the future; the done state
indicates that the stream has terminated nominally; and the error
state indicates that the stream has terminated abnormally.
isCont() returns true when in the cont state;
isEmpty() returns true when in the empty state;
isDone() returns true when in the done state; and
isError() returns true when in the error state.
Non-blocking semantics
Input never blocks. An Input that would otherwise block
awaiting additional tokens instead enters the empty state,
signaling the input consumer to back off processing the input, but to remain
prepared to process additional input in the future. An Input enters
the done state when it encounters the final end of its input stream,
signaling the input consumer to terminate processing.
isPart() returns true if the Input will enter
the empty state after it consumes the last immediately available
token; it returns false if the Input will enter the
done state after it consumes the last immediately available token.
empty() returns an Input in the empty
state. done() returns an Input in the done
state.
Position tracking
The logical position of the current lookahead token is made available via
the mark() method, with optimized callouts for the byte offset, one-based line number, and one-based
column in the current line. The id() method
returns a diagnostic identifier for the token stream.
Cloning
An Input may be cloned to provide an indepently
mutable position into a shared token stream. Not all Input
implementations support cloning.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Inputclone()Returns an independently positioned view into the token stream, initialized with identical state to thisInput.intcolumn()Returns the one-based column number of the current lookahead token, relative to the current line in the stream.static Inputdone()Returns anInputin the done state.static InputReturns anInputin the done state, at themarkposition of a token stream logically identified byid.static Inputdone(Object id, Mark mark, InputSettings settings) Returns anInputin the done state, at themarkposition of a token stream logically identified byid, with the givensettings.static Inputdone(InputSettings settings) Returns anInputin the done state, with the givensettings.static Inputempty()Returns anInputin the empty state.static InputReturns anInputin the empty state, at themarkposition of a token stream logically identified byid.static Inputempty(Object id, Mark mark, InputSettings settings) Returns anInputin the empty state, at themarkposition of a token stream logically identified byid, with the givensettings.static Inputempty(InputSettings settings) Returns anInputin the empty state, with the givensettings.static InputReturns anInputin the error state, with the given inputerror.static InputReturns anInputin the error state, with the given inputerror, at themarkposition of a token stream logically identified byid.static Inputerror(Throwable error, Object id, Mark mark, InputSettings settings) Returns anInputin the error state, with the given inputerror, at themarkposition of a token stream logically identified byid, with the givensettings.static Inputerror(Throwable error, InputSettings settings) Returns anInputin the error state, with the given inputerrorandsettings.Returns anInputequivalent to thisInput, but whose behavior may be altered by the given out-of-bandcondition.abstract inthead()Returns the current lookahead token, if thisInputis in the cont state.abstract Objectid()Returns an object that identifies the token stream, ornullif the stream is unidentified.abstract InputReturns anInputequivalent to thisInput, but logically identified by the given–possiblynull–id.abstract booleanisCont()Returnstruewhen alookeaheadtoken is immediately available.abstract booleanisDone()Returnstruewhen no lookahead token is currently available, and no additional input will ever become available.abstract booleanisEmpty()Returnstruewhen no lookahead token is currently available, but additional input may be available in the future.abstract booleanisError()Returnstruewhen no lookahead token is currently available due to an error with the token stream.abstract booleanisPart()Returnstrueif this is a partialInputwill that enter the empty state after it consumes the last available input token.abstract InputisPart(boolean isPart) Returns a partialInputequivalent to thisInput, ifisPartistrue; returns a finalInputequivalent to thisInputifisPartisfalse.intline()Returns the one-based line number of the current lookahead token, relative to the start of the stream.abstract Markmark()Returns the position of the current lookahead token, relative to the start of the stream.abstract InputReturns anInputequivalent to thisInput, but logically positioned at the givenmark.longoffset()Returns the byte offset of the current lookahead token, relative to the start of the stream.abstract InputReturns anInputequivalent to thisInput, but repositioned to the givenmark.abstract InputSettingssettings()Returns theInputSettingsused to configure the behavior of input consumers that read from thisInput.abstract Inputsettings(InputSettings settings) Returns anInputequivalent to thisInput, but with the given inputsettings.abstract Inputstep()Returns anInputequivalent to thisInput, but advanced to the next token.trap()Returns the input error.
-
Constructor Details
-
Input
public Input()
-
-
Method Details
-
isCont
public abstract boolean isCont()Returnstruewhen alookeaheadtoken is immediately available. i.e. thisInputis in the cont state. -
isEmpty
public abstract boolean isEmpty()Returnstruewhen no lookahead token is currently available, but additional input may be available in the future. i.e. thisInputis in the empty state. -
isDone
public abstract boolean isDone()Returnstruewhen no lookahead token is currently available, and no additional input will ever become available. i.e. thisInputis in the done state. -
isError
public abstract boolean isError()Returnstruewhen no lookahead token is currently available due to an error with the token stream. i.e. thisInputis in the error state. Whentrue,trap()will return the input error. -
isPart
public abstract boolean isPart()Returnstrueif this is a partialInputwill that enter the empty state after it consumes the last available input token. -
isPart
Returns a partialInputequivalent to thisInput, ifisPartistrue; returns a finalInputequivalent to thisInputifisPartisfalse. The caller's reference tothisInputshould be replaced by the returnedInput. -
head
public abstract int head()Returns the current lookahead token, if thisInputis in the cont state.- Throws:
InputException- if thisInputis not in the cont state.
-
step
Returns anInputequivalent to thisInput, but advanced to the next token. Returns anInputin the error state if thisInputis not in the cont state. The caller's reference tothisInputshould be replaced by the returnedInput. -
seek
Returns anInputequivalent to thisInput, but repositioned to the givenmark. Returns anInputin the error state if thisInputdoes not support seeking, or if thisInputis unable to reposition to the givenmark. The caller's reference tothisInputshould be replaced by the returnedInput. -
fork
Returns anInputequivalent to thisInput, but whose behavior may be altered by the given out-of-bandcondition. The caller's reference tothisInputshould be replaced by the returnedInput. -
trap
Returns the input error. Only guaranteed to return an error when in the error state.- Throws:
InputException- if thisInputis not in the error state.
-
id
Returns an object that identifies the token stream, ornullif the stream is unidentified. -
id
Returns anInputequivalent to thisInput, but logically identified by the given–possiblynull–id. The caller's reference tothisInputshould be replaced by the returnedInput. -
mark
Returns the position of the current lookahead token, relative to the start of the stream. -
mark
Returns anInputequivalent to thisInput, but logically positioned at the givenmark. The physical position in the input stream is not modified. The caller's reference tothisInputshould be replaced by the returnedInput. -
offset
public long offset()Returns the byte offset of the current lookahead token, relative to the start of the stream. -
line
public int line()Returns the one-based line number of the current lookahead token, relative to the start of the stream. -
column
public int column()Returns the one-based column number of the current lookahead token, relative to the current line in the stream. -
settings
Returns theInputSettingsused to configure the behavior of input consumers that read from thisInput. -
settings
Returns anInputequivalent to thisInput, but with the given inputsettings. The caller's reference tothisInputshould be replaced by the returnedInput. -
clone
Returns an independently positioned view into the token stream, initialized with identical state to thisInput.- Overrides:
clonein classObject- Throws:
UnsupportedOperationException- if thisInputcannot be cloned.
-
empty
Returns anInputin the empty state. -
empty
Returns anInputin the empty state, with the givensettings. -
empty
Returns anInputin the empty state, at themarkposition of a token stream logically identified byid. -
empty
Returns anInputin the empty state, at themarkposition of a token stream logically identified byid, with the givensettings. -
done
Returns anInputin the done state. -
done
Returns anInputin the done state, with the givensettings. -
done
Returns anInputin the done state, at themarkposition of a token stream logically identified byid. -
done
Returns anInputin the done state, at themarkposition of a token stream logically identified byid, with the givensettings. -
error
Returns anInputin the error state, with the given inputerror. -
error
Returns anInputin the error state, with the given inputerrorandsettings. -
error
Returns anInputin the error state, with the given inputerror, at themarkposition of a token stream logically identified byid. -
error
Returns anInputin the error state, with the given inputerror, at themarkposition of a token stream logically identified byid, with the givensettings.
-