Libraries
Articles

FixedFormat4j

From Libzter

Share/Save/Bookmark
Jump to: navigation, search


fixedformat4j

Developer(s)Jacob von Eyben
Initial Release
Current Version1.3.1
Language(s)Java
Licence(s)Apache license 2.0
Platform(s)Cross Platform


Contents

[edit] Overview

Fixedformat4j is a simple library specialized in reading fixed format flat text files. This is stil a common format in legacy systems/mainframes.


[edit] Specifications

Fixedformat4j depends on the Apache java libraries commons-lang and commons-logging.

[edit] Features

  • Single line fixed format parsing
  • Record typ specifications.

[edit] Installation

You will have to copy the jar file and make sure it is included in you classpath. You will also have to make sure commons-lang and commons-logging are installed (or in your java classpath).

[edit] Usage

This is a sample of a flat fixed format data file

     568   Say Hello to my little friend
    1456   John. D. Smith
 4242424   Some text

This code defines a Record (line) and how it is formated

public class MyRecord{
  private int myInt;
  private String myString;
 
 
   @Field(offset=1,length=9,align=Align.RIGHT)
   public int getInt(){ return myInt;}
   public void setInt(int num){myInt=num;}
 
   @Field(offset=12,length=30)
   public String getStr(){ return myString;}
   public void setStr(String str){myString=str;}
 }

Example of usage.

public class Foo{
   private FixedFormatManager  fixed = new FixedFormatManagerImpl();
 
   // .. Add code to open the text file and read each line with readLine().
 
 
    private MyRecord readLine(BufferedReader in){
      MyRecord r = fixed.load(MyRecord.class,in.ReadLine());
      return r;
    }
}

[edit] Resources

Download

Project page and documentation


Library Navigation

  • Language

  • Category
Google AdSense