Skip to content

beta0c7/beanio-usage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

beanio-usage

Quick example of how to unmarshal a plain text file delimited by size using the Beanio library for Java.

Steps

- Create a POJO file with the required fields
- Anotate the class with '@Record'
- Define the field start position and lenght with '@Field' annotation
- With StreamFactory, define a reader with the annotated POJO
    - BeanIo supports multiple reader formats. The format 'fixedlenght' is used here.
- It is possible to skip rows with 'BeanReader.skip(<numberOfRows>)' method

Device.java

@Record
public class Device {

    @Field(at = 0, length = 15)
    private String macAddress;

    @Field(at = 15, length = 15)
    private String ipAddress;

    @Field(at = 31, length = 9)
    private String hostInterface;
    ...

Parser.java

    public Parser(){
        factory = StreamFactory.newInstance();
        factory.define(new StreamBuilder("devices")
                     .format("fixedlength")
                     .addRecord(Device.class)
        );
     }

    public void readFileUsingBeanIo(File file, int skipHeaders) {
        BeanReader in = factory.createReader("devices", file);
        in.skip(skipHeaders);
        mapRows(in);
    }

Test Results

Results


Reference

http://beanio.org/2.1/docs/reference/index.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages