FLDA supports reading data as well as writing data of records with a fix size.
Fix size means:
- each record has n Attributes. An Attribute has an index.
- or: each record has a fix length. An Attribute has an index and a length.
This project is only the core. For some usages of this project see:
Fixed-length data consists of attributes that each have a specific position and length. Hence, every n-th attribute begins at the same character-index. In this example, every name of an item begins at character-index 10 and every amount of items begins at character-index 16:
Fruit Cherry30
Fruit Apple 5
VegetablePotato23
Character-separated data consists of attributes that are separated by a character. In this example, the attributes
are semicolon-separated and each record consists of three Attributes. The record type is List<String>.
Fruit;Cherry;30
Fruit;Apple;5
Vegetable;Potato;23
To use FLDA, include the following artifact:
<dependency>
<groupId>com.github.tinosteinort</groupId>
<artifactId>flda-core</artifactId>
<version>2.0.0</version>
</dependency>The Automatic Module Name of this library is:
com.github.tinosteinort.flda.accessor
Within the Accessor Concept there are different parts:
- the fixed size data record
- the definition of an attribute
- an accessor
This is just the part of data to read from or to write to.
This is the information how an attribute is addressed. There are different questions to answer:
- of which type is the attribute?
- on which index is the attribute located?
- how long (e.g. in characters or bytes) is the attribute?
For some record types not all questions are relevant. For an index based record type, there is no need to know the size of one attribute.
Example of a FixedLengthString attribute with index and length:
FixedLengthStringAttribute<String> FIRST_NAME = new FixedLengthStringAttribute<>(String.class, 0, 10);A ReadAccessor reads from a record and a WriteAccessor writes to the record. Therefore an attribute definition
is needed. An AccessorConfig is needed too.
Read Example:
AccessorConfig<FixedLengthString, FixedLengthStringAttribute<?>> config = ...
ReadAccessor<FixedLengthString, FixedLengthStringAttribute<?>> readAccessor = new ReadAccessor<>(config, datarecord)
String firstname = readAccessor.read(FIRST_NAME)Example for write a record:
AccessorConfig<FixedLengthString, FixedLengthStringAttribute<?>> config = ...
WriteAccessor<FixedLengthString, FixedLengthStringAttribute<?>> writeAccessor = new WriteAccessor<>(config, record);
writeAccessor.write(PersonDescriptor.FIRST_NAME, person.getFirstname());A record factory is used by AccessorConfig.createNewRecord. To use this
method it is required to register a record factory:
AccessorConfig<FixedLengthString, FixedLengthStringAttribute<?>> config = new AccessorConfigBuilder<FixedLengthString, FixedLengthStringAttribute<?>>()
// ...
.withRecordFactory(new FixedLengthStringFactory(23, ' '))
.build();The advantage of using a record factory is, that the code to create a new record is in one place.
There are different predefined record factories:
FixedLengthString=>FixedLengthStringFactoryStringList=>StringListFactory
It is possible to validate the records automatically. Just register the desired validators:
SizeValidator validator = new SizeValidator(5);
AccessorConfig<List<String>, StringListAttribute<?>> config =
new AccessorConfigBuilder<List<String>, StringListAttribute<?>>()
// ...
.withReadValidator(validator)
.withWriteValidator(validator)
.build();There are different predefined validators:
FixedLengthString=>LengthValidatorStringList=>SizeValidator
- Move
StringFitterfromcom.github.tinosteinort.flda.interfaces.fixedlengthstring.writertocom.github.tinosteinort.flda.interfaces.fixedlengthstring StringFitteris renamed toStringUtils- Extract
StringFitter.Alignmentinto own Class:com.github.tinosteinort.flda.interfaces.fixedlengthstring.Alignment - Remove
AlignmentClass from FixedLengthString Writer Classes intocom.github.tinosteinort.flda.interfaces.fixedlengthstring.FixedLengthStringAttribute - Remove
fillerchar from FixedLengthString Writer Classes intocom.github.tinosteinort.flda.interfaces.fixedlengthstring.FixedLengthStringAttribute - Method
FixedLengthString#getString()replaced byFixedLengthString#toString()- Output of old
FixedLengthString#toString()Method is not supported anymore
- Output of old
- Class
StringReaderis replaced by MethodStringUtils#readAndTrim() FixedLenghtStringimplementsCharSequence- API Update: move filler char and alignment into
FixedLengthStringAttribute - split project
fldainflda-core,flda-fixedlengthstringandflda-stringlist - introduce own
RecordFactory<T>interface.Supplier<T>was used before - change
AccessorConfigfrom interface to abstract class. Needed to clean up the API