Class FlatFieldFormatSupport
- java.lang.Object
-
- org.beanio.internal.parser.format.flat.FlatFieldFormatSupport
-
- All Implemented Interfaces:
FieldFormat
,FlatFieldFormat
- Direct Known Subclasses:
DelimitedFieldFormat
,FixedLengthFieldFormat
public abstract class FlatFieldFormatSupport extends java.lang.Object implements FlatFieldFormat
Base class forFlatFieldFormat
implementations.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description FlatFieldFormatSupport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.String
extract(UnmarshallingContext context, boolean reporting)
Extracts the field text from a record.protected abstract java.lang.String
extractFieldText(UnmarshallingContext context, boolean reporting)
java.lang.String
getName()
Returns the field name.FieldPadding
getPadding()
Returns the field padding.int
getPosition()
Returns the field position.int
getSize()
Returns the size of the field.int
getUntil()
void
insertField(MarshallingContext context, java.lang.String text)
Inserts field text into a record.protected abstract void
insertFieldText(MarshallingContext context, java.lang.String text, boolean commit)
boolean
insertValue(MarshallingContext context, java.lang.Object value)
Inserts a value into a record.boolean
isLazy()
TODO rename isLazy to something better?? Returns whether this field is optionally present in the record.boolean
isNillable()
Returns whether this field is nillable.void
setLazy(boolean lazy)
void
setName(java.lang.String name)
Sets the field name.void
setPadding(FieldPadding padding)
Sets the field padding.void
setPosition(int position)
void
setUntil(int until)
java.lang.String
toString()
-
-
-
Method Detail
-
insertValue
public boolean insertValue(MarshallingContext context, java.lang.Object value)
Description copied from interface:FieldFormat
Inserts a value into a record. This method is called before type conversion. If the method returns false, type conversion is invoked andFieldFormat.insertField(MarshallingContext, String)
is called. If the method returns true,FieldFormat.insertField(MarshallingContext, String)
is not invoked.- Specified by:
insertValue
in interfaceFieldFormat
- Parameters:
context
- theMarshallingContext
value
- the value to insert into the record- Returns:
- true if type conversion is required and
FieldFormat.insertField(MarshallingContext, String)
must be invoked, false otherwise
-
insertField
public void insertField(MarshallingContext context, java.lang.String text)
Inserts field text into a record.- Specified by:
insertField
in interfaceFieldFormat
- Parameters:
context
- theMarshallingContext
holding the recordtext
- the field text to insert into the record
-
insertFieldText
protected abstract void insertFieldText(MarshallingContext context, java.lang.String text, boolean commit)
-
extract
public java.lang.String extract(UnmarshallingContext context, boolean reporting)
Description copied from interface:FieldFormat
Extracts the field text from a record. Returnsnull
if the field was not present in the record.May return
Value.INVALID
if the field is invalid, orValue.NIL
if the field is explicitly set to nil or null such as in an XML or JSON formatted stream.Implementations should also remove any field padding before returning the text.
- Specified by:
extract
in interfaceFieldFormat
- Parameters:
context
- theUnmarshallingContext
holding the record- Returns:
- the field text
-
extractFieldText
protected abstract java.lang.String extractFieldText(UnmarshallingContext context, boolean reporting)
-
getName
public java.lang.String getName()
Returns the field name.- Returns:
- the field name
-
setName
public void setName(java.lang.String name)
Sets the field name.- Parameters:
name
- the field name
-
getPosition
public int getPosition()
Description copied from interface:FlatFieldFormat
Returns the field position.In a delimited/CSV stream format, the position is the index of the field in the record starting at 0. For example, the position of field2 in the following comma delimited record is 1:
field1,field2,field3
In a fixed length stream format, the position is the index of the first character of the field in the record, also starting at 0. For example, the position of field2 in the following record is 6:
field1field2field3
- Specified by:
getPosition
in interfaceFlatFieldFormat
- Returns:
- the field position
-
setPosition
public void setPosition(int position)
-
getUntil
public int getUntil()
-
setUntil
public void setUntil(int until)
-
getSize
public int getSize()
Description copied from interface:FieldFormat
Returns the size of the field. Fixed length formats should return the field length, while other formats should simply return 1.- Specified by:
getSize
in interfaceFieldFormat
- Returns:
- the size of the field
-
isNillable
public boolean isNillable()
Description copied from interface:FieldFormat
Returns whether this field is nillable.- Specified by:
isNillable
in interfaceFieldFormat
- Returns:
- true if nillable, false otherwise
-
getPadding
public FieldPadding getPadding()
Returns the field padding.- Returns:
- the
FieldPadding
-
setPadding
public void setPadding(FieldPadding padding)
Sets the field padding.- Parameters:
padding
- theFieldPadding
-
isLazy
public boolean isLazy()
Description copied from interface:FieldFormat
TODO rename isLazy to something better?? Returns whether this field is optionally present in the record.- Specified by:
isLazy
in interfaceFieldFormat
- Returns:
- true if lazy, false otherwise
-
setLazy
public void setLazy(boolean lazy)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-