- 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 MarshallingConfigconfigTheMarshallingConfig.protected StringnameThe current name.protected StructuredReader.Statestate
-
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:
getStatein interfaceStructuredReader- Returns:
- the current state of this reader.
-
readStartObject
public boolean readStartObject()
- Specified by:
readStartObjectin interfaceStructuredReader- Returns:
trueif pointing to the start of an object,falseotherwise.- See Also:
StructuredWriter.writeStartObject()
-
readStartArray
public boolean readStartArray()
- Specified by:
readStartArrayin interfaceStructuredReader- Returns:
trueif pointing to the start of an object,falseotherwise.- See Also:
StructuredWriter.writeStartArray()
-
readEnd
public boolean readEnd()
- Specified by:
readEndin interfaceStructuredReader- Returns:
trueif the end of anarrayorobjecthas been reached.
-
isDone
public boolean isDone()
- Specified by:
isDonein interfaceStructuredReader- Returns:
trueif all data has been read and the end of the stream has been reached,falseotherwise.
-
readValueAsNumberString
protected String readValueAsNumberString()
- Returns:
- the value as
Stringbut assuring it as number. - See Also:
StructuredReader.readValueAsString()
-
expect
protected void expect(StructuredReader.State expected)
Verifies that thecurrent stateis the same as the given states.- Parameters:
expected- first accepted state.
-
expect
protected void expect(StructuredReader.State expected, StructuredReader.State expected2)
Verifies that thecurrent stateis 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 stateis 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 stateis 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 ornullif 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:
readValueAsIntegerin interfaceStructuredReader- Returns:
- reads the value as
Integer. - See Also:
StructuredReader.readValue(Class)
-
readValueAsLong
public Long readValueAsLong()
- Specified by:
readValueAsLongin interfaceStructuredReader- Returns:
- reads the value as
Long. - See Also:
StructuredReader.readValue(Class)
-
readValueAsDouble
public Double readValueAsDouble()
- Specified by:
readValueAsDoublein interfaceStructuredReader- Returns:
- reads the value as
Double. - See Also:
StructuredReader.readValue(Class)
-
readValueAsFloat
public Float readValueAsFloat()
- Specified by:
readValueAsFloatin interfaceStructuredReader- Returns:
- reads the value as
Float. - See Also:
StructuredReader.readValue(Class)
-
readValueAsShort
public Short readValueAsShort()
- Specified by:
readValueAsShortin interfaceStructuredReader- Returns:
- reads the value as
Short. - See Also:
StructuredReader.readValue(Class)
-
readValueAsByte
public Byte readValueAsByte()
- Specified by:
readValueAsBytein interfaceStructuredReader- Returns:
- reads the value as
Byte. - See Also:
StructuredReader.readValue(Class)
-
readValueAsBigInteger
public BigInteger readValueAsBigInteger()
- Specified by:
readValueAsBigIntegerin interfaceStructuredReader- Returns:
- reads the value as
BigInteger. - See Also:
StructuredReader.readValue(Class)
-
readValueAsBigDecimal
public BigDecimal readValueAsBigDecimal()
- Specified by:
readValueAsBigDecimalin 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:StructuredReaderThis method may be called if thecurrent stateisStructuredReader.State.START_OBJECTto read the object into the givenMap. After the call of this method thestatewill point to thenextone after the correspondingStructuredReader.State.END_OBJECT.- Specified by:
readObjectin interfaceStructuredReader- Parameters:
map- theMapwhere to add the properties. UnlikeStructuredReader.readValue(boolean)this allows you to choose theMapimplementation.
-
readArray
public void readArray(Collection<Object> array)
Description copied from interface:StructuredReaderThis method may be called called if thecurrent stateisStructuredReader.State.START_ARRAYto read the array into the givenCollection. After the call of this method thestatewill point to thenextone after the correspondingStructuredReader.State.END_ARRAY.- Specified by:
readArrayin interfaceStructuredReader- Parameters:
array- theCollectionwhere to add thevalues.
-
skipValue
public void skipValue()
Description copied from interface:StructuredReaderSkips 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:
skipValuein interfaceStructuredReader
- If currently at
-
-