Ancient Programming

What I encounter in my software part of life is in danger of being commented upon here

  • Jacob von Eyben

    MeAfter finishing my education in 2002 I have been working as a Systems Architect for the danish consulting company Nordija. My primary area is the Java platform with particular interest for what could be called lightweight architecture. That includes technologies like Spring, EJB 3, Hibernate, JPA, Acegi etc. Besides the Java platform I have interest in other languages like Ruby, Actionscript 3 (for flex development) and others.

Manipulating fixed formatted text files

Posted by jeyben on March 1st, 2008

I am working on a project where we need to manipulate fixed formatted text files. The fixed formatted files are used as protocol for interchanging data between some legacy mainframe systems. I have been looking for some already existing api for manipulating these fixed formatted data but couldn’t find any.

So this weekend I started implementing a solution based on some of the idea´s we got along the way.

Basics

I have a few goals for the api:

  1. A line of text should be easily manipulated as a java object.
  2. Should require a minimum of own code to manipulate the text string.
  3. Use annotations to define attributes like:
    • Offset in text
    • The fixed length of the text
    • padding direction and padding character

The api usage could look something like this:

public interface Record {

  // use if you need a reference to the manipulated string - could be a constructor
  void initialize(StringBuffer buffer);

  // use if you don't need a reference to the manipulated string - could be a constructor
  void initialize(String string);

  String export(); //export string
}
...
public abstract class MyRecord implements Record {

  @FixedFormatField(offset = 10, length=20, paddingChar='0')
  public abstract void setMyInteger(Integer myInteger);

  @FixedFormatField(offset = 10, length=20, paddingChar='0')
  public abstract Integer getMyInteger();
}


And then a factory to create instances of the Record. Maybe annotations on fields would be nice as well as dublicating annotations for setter/getter is waste and could be error-prone.

This is the part I am working on at the moment and getting some hands-on experience with javassist. I will get back to that in another post.

Fixedformat4j

I have named the api fixedformat4j and I will opensource it as soon as I have something worth for others to use. Hopefully it won’t end up as one of my numerous 23% finished projects…

7 Responses to “Manipulating fixed formatted text files”

  1. Felipe Gonçalves Coury Says:

    Hey,

    You might want to take a look at JFileHelpers library I ported from C#’s FileHelpers. Take a look at this - translated from Portuguese - article:

    http://tinyurl.com/38rawn

    Let me know what your thoughts are.

    Best regards,
    Felipe Coury

  2. Felipe Gonçalves Coury Says:

    … the code snippets were pretty much messed up upon automatic translation, so for referencing to snippets, take a look at the original article:

    http://blog.felipecoury.com/jep/2008/02/java-text-import-export.html

    Regards,
    Felipe.

  3. Aldrin Leal Says:

    Jacob,

    I wrote some code a while ago. You might see a interface I made in order to let you easily build a set of beans able to handle a given record @ http://www.leal.eng.br/apps/mapper/launch

  4. ashish Says:

    if you can talk to the mainframe developers, you can get the cobol data structures and then use that to quickly automate writing the java classes. The perl world did this a looog time ago.

    See this http://search.cpan.org/~grommel/Convert-IBM390-0.23/IBM390.pod

  5. ruben Says:

    Take a peek, maybe it fits your needs:

    jffp

  6. Ancient Programming » Blog Archive » fixedformat4j api - bring on your feedback! Says:

    […] Manipulating fixed formatted text files […]

  7. Felipe Gonçalves Coury Says:

    I have just created the website for JFileHelpers, so if you are interested on joining forces:

    http://www.jfilehelpers.com

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>