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");
        } else {
            System.out.println("Creating data files with default size.");
        GenerateData gd = new GenerateData();

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/");
            System.out.println("/tmp/ created");

            for (int x=0;x<nums.length;x++){
            System.out.println("/tmp/ created");

      } catch (Exception ex) {

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.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s