T
- The type that is parsed.@PublicEvolving public abstract class FieldParser<T> extends Object
The parsers do not throw exceptions in general, but set an error state. That way, they can be used in functions that ignore invalid lines, rather than failing on them.
Modifier and Type | Class and Description |
---|---|
static class |
FieldParser.ParseErrorState
An enumeration of different types of errors that may occur.
|
Constructor and Description |
---|
FieldParser() |
Modifier and Type | Method and Description |
---|---|
abstract T |
createValue()
Returns an instance of the parsed value type.
|
static boolean |
delimiterNext(byte[] bytes,
int startPos,
byte[] delim)
Checks if the delimiter starts at the given start position of the byte array.
|
FieldParser.ParseErrorState |
getErrorState()
Gets the error state of the parser, as a value of the enumeration
FieldParser.ParseErrorState . |
abstract T |
getLastResult()
Gets the parsed field.
|
static <T> Class<FieldParser<T>> |
getParserForType(Class<T> type)
Gets the parser for the type specified by the given class.
|
abstract int |
parseField(byte[] bytes,
int startPos,
int limit,
byte[] delim,
T reuse)
Parses the value of a field from the byte array.
|
protected void |
setErrorState(FieldParser.ParseErrorState error)
Sets the error state of the parser.
|
public abstract int parseField(byte[] bytes, int startPos, int limit, byte[] delim, T reuse)
bytes
- The byte array that holds the value.startPos
- The index where the field startslimit
- The limit unto which the byte contents is valid for the parser. The limit is the
position one after the last valid byte.delim
- The field delimiter characterreuse
- An optional reusable field to hold the valuepublic abstract T getLastResult()
parseField(byte[], int, int, byte[], Object)
. It objects are mutable and reused, it will return
the object instance that was passed the parse function.public abstract T createValue()
public static final boolean delimiterNext(byte[] bytes, int startPos, byte[] delim)
bytes
- The byte array that holds the value.startPos
- The index of the byte array where the check for the delimiter starts.delim
- The delimiter to check for.protected void setErrorState(FieldParser.ParseErrorState error)
error
- The error state to set.public FieldParser.ParseErrorState getErrorState()
FieldParser.ParseErrorState
.
If no error occurred, the error state will be FieldParser.ParseErrorState.NONE
.public static <T> Class<FieldParser<T>> getParserForType(Class<T> type)
type
- The class of the type to get the parser for.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.