- java.lang.Object
-
- io.github.mmm.marshall.AbstractStructuredReader
-
- All Implemented Interfaces:
StructuredReader
,AutoCloseable
public abstract class AbstractStructuredReader extends Object implements StructuredReader
Abstract base implementation ofStructuredReader
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.github.mmm.marshall.StructuredReader
StructuredReader.State
-
-
Field Summary
Fields Modifier and Type Field Description protected MarshallingConfig
config
TheMarshallingConfig
.protected String
name
The current name.protected StructuredReader.State
state
-
Constructor Summary
Constructors Constructor Description AbstractStructuredReader(MarshallingConfig config)
The constructor.
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.mmm.marshall.StructuredReader
close, next, readName, readValue, readValue, readValueAsBoolean, readValueAsString
-
-
-
-
Field Detail
-
config
protected final MarshallingConfig config
TheMarshallingConfig
.
-
name
protected String name
The current name.- See Also:
StructuredReader.readName()
-
state
protected StructuredReader.State state
- See Also:
getState()
-
-
Constructor Detail
-
AbstractStructuredReader
public AbstractStructuredReader(MarshallingConfig config)
The constructor.- Parameters:
config
- theMarshallingConfig
.
-
-
Method Detail
-
getState
public StructuredReader.State getState()
- Specified by:
getState
in interfaceStructuredReader
- Returns:
- the current state of this reader.
-
readStartObject
public boolean readStartObject()
- Specified by:
readStartObject
in interfaceStructuredReader
- Returns:
true
if pointing to the start of an object,false
otherwise.- See Also:
StructuredWriter.writeStartObject()
-
readStartArray
public boolean readStartArray()
- Specified by:
readStartArray
in interfaceStructuredReader
- Returns:
true
if pointing to the start of an object,false
otherwise.- See Also:
StructuredWriter.writeStartArray()
-
readEnd
public boolean readEnd()
- Specified by:
readEnd
in interfaceStructuredReader
- Returns:
true
if the end of anarray
orobject
has been reached.
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfaceStructuredReader
- Returns:
true
if all data has been read and the end of the stream has been reached,false
otherwise.
-
readValueAsNumberString
protected String readValueAsNumberString()
- Returns:
- the value as
String
but assuring it as number. - See Also:
StructuredReader.readValueAsString()
-
expect
protected void expect(StructuredReader.State expected)
Verifies that thecurrent state
is the same as the given states.- Parameters:
expected
- first accepted state.
-
expect
protected void expect(StructuredReader.State expected, StructuredReader.State expected2)
Verifies that thecurrent state
is one of the given states.- Parameters:
expected
- first accepted state.expected2
- second accepted state.
-
expect
protected void expect(StructuredReader.State expected, StructuredReader.State expected2, StructuredReader.State expected3)
Verifies that thecurrent state
is one of the given states.- Parameters:
expected
- first accepted state.expected2
- second accepted state.expected3
- third accepted state.
-
expectNot
protected void expectNot(StructuredReader.State unexpected)
Verifies that thecurrent state
is not the same as the given state.- Parameters:
unexpected
- the unexpected state.
-
handleValueParseError
protected RuntimeException handleValueParseError(String value, Class<?> typeClass, Throwable e)
- Parameters:
value
- the value that was read.typeClass
- the expected type.e
- a potential error that occurred ornull
if no cause.- Returns:
- nothing. Will always throw
IllegalStateException
. However to signal the compiler that the program flow will exit with the call of this function you may prefix it with "throw
".
-
readValueAsInteger
public Integer readValueAsInteger()
- Specified by:
readValueAsInteger
in interfaceStructuredReader
- Returns:
- reads the value as
Integer
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsLong
public Long readValueAsLong()
- Specified by:
readValueAsLong
in interfaceStructuredReader
- Returns:
- reads the value as
Long
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsDouble
public Double readValueAsDouble()
- Specified by:
readValueAsDouble
in interfaceStructuredReader
- Returns:
- reads the value as
Double
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsFloat
public Float readValueAsFloat()
- Specified by:
readValueAsFloat
in interfaceStructuredReader
- Returns:
- reads the value as
Float
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsShort
public Short readValueAsShort()
- Specified by:
readValueAsShort
in interfaceStructuredReader
- Returns:
- reads the value as
Short
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsByte
public Byte readValueAsByte()
- Specified by:
readValueAsByte
in interfaceStructuredReader
- Returns:
- reads the value as
Byte
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsBigInteger
public BigInteger readValueAsBigInteger()
- Specified by:
readValueAsBigInteger
in interfaceStructuredReader
- Returns:
- reads the value as
BigInteger
. - See Also:
StructuredReader.readValue(Class)
-
readValueAsBigDecimal
public BigDecimal readValueAsBigDecimal()
- Specified by:
readValueAsBigDecimal
in interfaceStructuredReader
- Returns:
- reads the value as
BigDecimal
. - See Also:
StructuredReader.readValue(Class)
-
readValue
public Object readValue(boolean recursive)
Description copied from interface:StructuredReader
-
readObject
public void readObject(Map<String,Object> map)
Description copied from interface:StructuredReader
This method may be called if thecurrent state
isStructuredReader.State.START_OBJECT
to read the object into the givenMap
. After the call of this method thestate
will point to thenext
one after the correspondingStructuredReader.State.END_OBJECT
.- Specified by:
readObject
in interfaceStructuredReader
- Parameters:
map
- theMap
where to add the properties. UnlikeStructuredReader.readValue(boolean)
this allows you to choose theMap
implementation.
-
readArray
public void readArray(Collection<Object> array)
Description copied from interface:StructuredReader
This method may be called called if thecurrent state
isStructuredReader.State.START_ARRAY
to read the array into the givenCollection
. After the call of this method thestate
will point to thenext
one after the correspondingStructuredReader.State.END_ARRAY
.- Specified by:
readArray
in interfaceStructuredReader
- Parameters:
array
- theCollection
where to add thevalues
.
-
skipValue
public void skipValue()
Description copied from interface:StructuredReader
Skips the current value. Should be called afterStructuredReader.readName()
.- If currently at
start of object
, skip that entire object. - If currently at
start of array
, skip the entire array. - If currently at a
single value
, skip that value.
- Specified by:
skipValue
in interfaceStructuredReader
- If currently at
-
-