Generating dump Java data files

Recently I have been running some disk I/O benchmarks, among others, with Java. I needed to check I/O operations performance with plain data files. I had to implement the following to generate dump data files to be used by the benchmark. I’m not going to comment a lot on that as it is pretty much straight forward.

Some variables declarations at first place:

    private int value = 0;
    public static int DATA_SIZE = 10000000; // 9.5MB
    private static byte[] b;
    private static int[] nums;
    private FileOutputStream byteFile;
    private DataOutputStream intFile;

The main method follows. If the user doesn’t provide any input then the default data size will be assumed, otherwise the one specified. There should be an exception handler there for checking the input format but with such a simple program it can be avoided:

    public static void main(String args[]){
        if (args.length != 0){
            DATA_SIZE = Integer.parseInt(args[0]);
            System.out.println("Creating data files with size: " + DATA_SIZE + " bytes");
            System.out.println("");
        } else {
            System.out.println("Creating data files with default size.");
            System.out.println("");
        }
        GenerateData gd = new GenerateData();
        gd.generate(DATA_SIZE);
    }

Followed by the GenerateData method that actually creates the data:

    public void generate(int size){
        b = new byte[size];
        nums = new int[size/4]; // Each int is 4 bytes

        for (int i=0;i<size;i++){
           int offset = (b.length - 1 - i) * 8;
           b[i] = (byte) ((value >>> offset) & 0xFF);
        }

        try {
            byteFile = new FileOutputStream("/tmp/rawbytearray.data");
            byteFile.write(b);
            byteFile.close();
            System.out.println("/tmp/rawbytearray.data created");

            for (int x=0;x<nums.length;x++){
                intFile.writeInt(nums[x]);
            }
            intFile.close();
            System.out.println("/tmp/datastream.data created");

      } catch (Exception ex) {
         System.out.println(ex);
      }
    }
byteFile

Both files can be found under /tmp. Obviously that wouldn’t work on Windows, but there was not intention from my part in running this in any non *nix system :). If you need to do so, just replace the path.

Advertisement

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