Ancient Programming

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

Fixedformat4j now supports primitive datatypes as well as innerclasses

Posted by Jacob von Eyben on October 16th, 2008

Support for primitive datatypes is added to the latest 1.2.1 release of fixedformat4j. I would like to thank Marcos Lois Bermúdez for contributing with this extension. The latest release can be downloaded here.

The same 1.2.1 release also fixed the bug that made it impossible to use annotate and format static nested classes and inner classes

The complete changelist can be found on the project website.

In a few days the release should be available from ibiblio.

I encourage all users of fixedformat4j to contribute or create issues if they find a bug or would like new features to be added.

Posted in fixedformat4j, java | No Comments »

Automatically reconnect to NAS under Mac OS X

Posted by Jacob von Eyben on June 27th, 2008

Mac OS X doesn’t remount network drives when booted. You have to do this yourselves.

You can easily automate this by creating an application using the automator and add it to your login items.

Automator - create application

You automator script should contain two items:

  • Get Specified Servers
  • Connect to Servers

Save the script as an application and put it into login items for your user account. This will execute your small application each time you login and you should be reconnected to your NAS on startup.

Posted in how to, mac | No Comments »

Fixedformat4j 1.2.0 released

Posted by Jacob von Eyben on June 12th, 2008

This evening I released a new version of fixedformat4j containing improved error reporting when failing to parse data using the FixedFormatManager.

The lack of good error reporting was a bit of a pain. It was not easy to see where in the parsing failed and it was not possible to get a complete list of format instructions.

A new ParseException is now thrown which contains the nessesary information.

See example of the new and improved stacktrace:

com.ancientprogramming.fixedformat4j.format.ParseException: failed to parse 'barfooba' at offset 16 as java.util.Date from 'foobarfoobarfoobarfoobar'. Got format instructions from com.ancientprogramming.fixedformat4j.format.impl.MyRecord.getDateData. See details{FormatContext{offset=16, dataType=java.util.Date, formatter=com.ancientprogramming.fixedformat4j.format.impl.ByTypeFormatter}, FormatInstructions{length=8, alignment=LEFT, paddingChar=' ', fixedFormatPatternData=FixedFormatPatternData{pattern='yyyyMMdd'}, fixedFormatBooleanData=FixedFormatBooleanData{trueValue='T', falseValue='F'}, fixedFormatNumberData=FixedFormatNumberData{signing=NOSIGN, positiveSign='+', negativeSign='-'}, fixedFormatDecimalData=FixedFormatDecimalData{decimals=2, useDecimalDelimiter=false, decimalDelimiter='.'}}}
 at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.readDataAccordingFieldAnnotation(
 at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.load(

Feel free to download the latest version and take a look at the changelist.

Posted in java | No Comments »

How to create macros for maven-site-plugin

Posted by Jacob von Eyben on June 5th, 2008

Many maven projects uses the maven site plugin to generate there documentation.

The maven-site-plugin uses the doxia to let authors write xdoc, apt and fml documents as the source for there project documentation. These written documents is processed by doxia to generate html and merged into the complete project site by the maven-site-plugin.

I found doxia and especially the apt language somehow lacking in functionality. I would like to use the syntaxhighlighter to be able to highlight code examples on the fixedformat4j project.

Doxia comes out-of-the-box with a small bunch of macros and you have the ability to write custom macros as well.

Custom macro

I wrote a simple macro based on the core snippet macro:


  Doxia :: syntaxhighlighter


Changes to the snippet plugin:

  public void execute(Sink sink, MacroRequest request)
      throws MacroExecutionException {
    System.out.println("ancientprogramming - running execute");
    String id = (String) request.getParameter("id");

    required(id, "id");

    String urlParam = (String) request.getParameter("url");

    String fileParam = (String) request.getParameter("file");

    String codeParam = (String) request.getParameter("code");

    required(codeParam, "code");

    URL url;

    if (!StringUtils.isEmpty(urlParam)) {
      try {
        url = new URL(urlParam);
      catch (MalformedURLException e) {
        throw new IllegalArgumentException(urlParam + " is a malformed URL");
    } else if (!StringUtils.isEmpty(fileParam)) {
      File f = new File(fileParam);

      if (!f.isAbsolute()) {
        f = new File(request.getBasedir(), fileParam);

      try {
        url = f.toURL();
      catch (MalformedURLException e) {
        throw new IllegalArgumentException(urlParam + " is a malformed URL");
    } else {
      throw new IllegalArgumentException("Either the 'url' or the 'file' param has to be given.");

    StringBuffer snippet;

    try {
      snippet = getSnippet(url, id);
    catch (IOException e) {
      throw new MacroExecutionException("Error reading snippet", e);

   sink.rawText("... syntaxhighlighter prefix ...");
   sink.rawText("... syntaxhighlighter postfix ...");

Note: wordpress obfuscates the above code where I wrote the syntax hightlighter pre and post fix. You can see what you actually should write at the syntaxhighligther project.

Use custom macro
To be able to use the macro you have to add your macro as dependency to the maven-site-plugin:


Now you can use the macro by writing the following in your apt files:


Change your site template
Before the the source can be highlighted in your documentation you should add the syntaxhighlighter javascript and stylesheets to your template.
See how to change your template here.

Posted in how to, java, maven | 1 Comment »

Fixedformat4j scores well on sonar

Posted by Jacob von Eyben on June 5th, 2008

Today I found fixedformat4j was obtained at sonarsoftware and it was exciting to see that it scored pretty well compared to some other very well known opensource projects like the commons series, some of the spring module and even the Apache Maven project.

I didn’t know sonar before today. They describe them as:

Sonar is an entreprise quality control tool, distributed under the terms of the GNU LGPL. Its basic purpose is to join existing continuous integration tools to place Java development projects under quality control.

Even though the metrics at sonar doesn’t draw the complete picture on how good or mature a project is, it still gives a hint.

Posted in fixedformat4j, java | No Comments »

Fixedformat4j 1.1.1 released

Posted by Jacob von Eyben on May 30th, 2008

We use fixedformat4j on my current project and I am developing fixedformat4j along the way. We have found the initial 1.0.0 release lacking in the ability to parse signed numbers like:

00011050+, that equals a two digit signed bigdecimal number 100.50

The fixedformatnumber annotation was introduced with the ability to add a signed attribute.

This is how you would annotate your method to be able to read and write a string like 000010050+:

@Field(offset = 1, length = 10, align = Align.RIGHT, paddingChar = '0')
@FixedFormatDecimal(useDecimalDelimiter = true)
@FixedFormatNumber(sign = Sign.APPEND)
public BigDecimal getBigDecimalData() {
  return bigDecimalData;

This was added in version 1.1.0, but some bugs was spotted and fixed so quickly a 1.1.1 version was released.

Feel free to download the latest version and take a look at the changelist.

Posted in fixedformat4j, java | No Comments »

Fixedformat4j released!

Posted by Jacob von Eyben on May 25th, 2008

At my current project we decided to use fixedformat4j.
So after all your feedback on my recent draft implementation I have been working quite hard this weekend to get fixedformat4j shined up.

The implementation looks pretty much what Niels proposed here and I implemented support for bigdecimal as Bob wished. That means that javassist is gone and fixedformat4j is now much less intrusive - you don’t have ti extend or implement anything to be able to load and export data.

You can see just how easy on the “getting started” at the frontpage of the project.

At this time of writing the api is only available through the download page, but I have send a maven upload request so soon it will be available from ibiblio.

Posted in fixedformat4j, java | No Comments »

fixedformat4j api - bring on your feedback!

Posted by Jacob von Eyben on March 17th, 2008

Earlier I wrote about reading and writing fixed formatted text files. Fortunately you all were eager to comment and provide suggestions on how to do this.
Inspired by your suggestions I decided to write an open source api to manipulate these fixed formatted data and promised to get back when I had code that was releasable.

That time is now!

I have deliberately not released a version yet as I would like some feedback before I commit myself to an api.

Please take a look at the documentation at and let me know your thoughts on the api.

The sourcecode can be browsed here.

I hope you will bring me some feedback before I do a final release.

Posted in fixedformat4j, java | 9 Comments »

Best practise when handling tags and branches (using subversion)

Posted by Jacob von Eyben on March 15th, 2008

This is the way I prefer tagging and branching my code when developing and releasing software. I use subversion but the overall guidelines can be applied by any versioning tool - say CVS.
I assume that you keep your source in the recommended structure:

  • trunk
  • tags
  • branches


Always use three digits to denote a release: major.minor.bugfix. ex: 1.2.0.

Name your trunk code like this: major.minor-SNAPSHOT, where major.minor denotes the next version to release. ex: The version in production is 1.2.0, you should name the trunk version 1.3-SNAPSHOT. I use snapshot to tell others that such a version is an arbitrary build along the way to a stable 1.3 release (The name ’snapshot’ is inherited from maven).


When releasing your code, you should tag the version you release by the version. This gives you a chance to always branch from that specific release if a bugfix is required. Ex: you 1.3-SNAPSHOT is ready to go into production. Tag a version by the name 1.3.0.
Even though some versioning tools allow you to commit to a tag, you should not do so. Tags is an image of the sourcecode at the release time!

At the same time you should change your trunk version t0 1.4-SNAPSHOT.


If your newly created release contains a bug that can’t wait to be fixed until your next trunk release, you should create a branch. Do so from your release tag.

You should name your branch like this: major_minor_bugfix, where major and minor is the same as the software in production. Ex: 1_3_bugfix.


I do not recommend having unmerged code on your branch for to long.
I suggest you you merge your software back to trunk for each fix you do. At least you should merge your branch back to trunk when your release a new version.

To assist you in this I suggest your commit message tells what revisions that is involved, - The revision from the branch and the revision on trunk.

Subversion commands

The following is the commands to use in subversion. I assume you use ssh to access subversion and the subversion repository is located at in the directory /var/subversion:

Tagging in subversion

$ svn copy svn+ssh:// \

Branching in subversion

Similar to tagging except the path.

$ svn copy svn+ssh:// \


I will split this into two cases. The case where you merge from the branch the first time and the following merges.

First merge from a branch

First you want to know what revision you are to merge from.That is the revision your branch was created at. You find that revision by executing the following command in your branch checkout:

$ svn log –stop-on-copy

That will list all your changes created on your branch since it was created. You can see the revision where your branch where created in the log output.

Knowing the revision you are ready to merge your changes. Change to a working copy of your trunk code and make sure your checkout is up to date by executing and findout the revision to merge into:

$ svn up

This will update your trunk copy and output the revision you are to merge into.
Now merge the changes by using the following command on your trunk working copy:

$ svn merge -r rev1:rev2 \

where rev1 equals the revision your branch was created and rev2 equals the revision on your trunk working copy.

Fix any conficts and commit your code. It is important that your commit message contains the to revisions you merged. I suggest you write the following. That message is important in later merges:

$ svn commit -m ‘Merged branches/1.0-bugfix rev1:rev2′

Following merges from branch

The next time you would like to merge, you execute the following in your working copy of your trunk code to find the revision to merge from:

$ svn log | grep -i merge

This assume that your commit message when merging contains the text merge - as we did in the first case.
The revision to use is the revision you merged into the last time +1.

Ex your log message looks something like this: ‘Merged project/brances/1_2_bugfix r1631:r1682 into head’, the revision to use is 1683.

With that version just repeat the steps from the ‘First merge from a branch’.

I suggest you read here to find more about branching and merging in subversion.

Posted in how to, subversion | 6 Comments »

Manipulating fixed formatted text files

Posted by Jacob von Eyben 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.


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.


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…

Posted in fixedformat4j, java | 6 Comments »