Java 1.6 fonts issue on Scientific Linux 5.2

On SL5.2 there is a missing link for the fonts to be used by JRE 1.6.0_11. The directory /usr/lib/jvm/java-1.6.0-sun-1.6.0.11/jre/lib/fonts points to /usr/share/fonts/java which actually doesn’t exist. However, the 1.5.0_16 JDK installation uses /usr/java/jdk1.5.0_16/jre/lib/fonts which contains all the right fonts. Altering JAVA_HOME to JDK 1.5.0_16 and launching the Java application again, it displays the fonts correctly. The quick workaround to get it working with 1.6.0_11 is to copy the existing JDK1.5.0_16 fonts directory under /usr/share/fonts/java.

Posted on scientific-linux-users: http://www.mail-archive.com/scientific-linux-users@listserv.fnal.gov/msg04301.html

Advertisement

Reading half file starting from random byte point in Java

I had to write a method within a Java testing application to read exactly the half file (no matter the size) of a binary file full of integers and store the integers in an array of integers. The method should calculate the random byte point and the size of the array based on the file size which is unknown.

At first place a File object is created and its size is identified:

    File dataFile = new File("/tmp/datastream.data");
    long data_size = dataFile.length();

One integer consists of 4 bytes. Therefore a valid integer within the file starts from point 4, and that is going to be the minimum value for the random. The maximum value is determined as the half size of the file in integers. If the data in the file were written using raw byte data stream, that would be divided by 2, but because one integer is 4 bytes, it has to be divided by 8.

    int minRandom = 4;
    int maxRandom = data_size / 8;

Having set the boundaries of the random byte, it has now to be calculated. The computed value must be a valid integer within the file, that means that its modulus when divided by 4 should be zero.

int randomNum;
do {
    randomNum = minRandom + (int)(Math.random() * ((maxRandom - minRandom) + 1));
} while (randomNum % 4 != 0);

Once the number is calculated, it is assigned as the start seek point. There’s a need for two variables with the same value as one of them will be used to identify the next seek byte in the file in order to read the next integer.

    seekByte = randomNum;
    initialSeekByte = randomNum;

Before reading the data, the array that will store the data has to be created. That will be the half size of the file considering that integers need to be stored:

    int_array = new int[data_size / 8];

Finally, the data can be fetched. Every next integer to be read must be the previous seek byte plus 4 to ensure a valid integer is read:

RandomAccessFile rafIN = new RandomAccessFile("/tmp/datastream.data", "r");
for (int i = 0; i < int_array.length; i++) {
    rafIN.seek(seekByte);
    int_array[i] = rafIN.readInt();
    seekByte += 4;
}

jIPFire – Java front-end for iptables

It was more than a year ago that I have started writting a Java front-end for Linux’s iptables. Mainly to make my life easier by using it on different Linux distributions, as well as to see how could that be implemented on Java. From the start date until a few months ago it was developing a bit slow but still in a stable tempo. I haven’t looked at it for the last six months, or so, as it became a lower priority task.

The latest is release is 0.4.8-beta can be found on http://jipfire.ilug.gr. The functions it offers are more or less what a desktop may need of iptables plus some more “advanced” features like interface forwarding, ip forwarding, port forwarding, port redirection, IP connection limit and burst limit being the most notable ones. The whole list of the application’s functions can be seen on the website so I’ll avoid duplicating the list over here.
The current release is available in tarball file, in Slackware package and in RPM package. The source code is available on a tarball as well.

An earlier release of jIPFire, 0.4.5-beta, comes with iloog 8.02 liveCD.

If anyone out there has the will and time to try out the application and give some feedback, ideas and development effort is more than welcome.

-> http://jipfire.ilug.gr
-> http://sourceforge.net/projects/jipfire

Sun Java σε Fedora: script

Αρκετά συχνά χρειάζεται να εγκαταστήσω τη Java από τη Sun σε κάποιο σύστημα Fedora. Το να κατεβάζεις το αρχείο κάθε φορά, να φτιάχνεις τα alternatives και το profile.d είναι λίγο βαρετό. Το παρακάτω script κάνει τη ζωή λίγο πιο εύκολη: setFedoraJava