Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import java.util.List;

public class Main {
    private static void makePerTilePerCycleFiles(final File parentDir, final int lane, final List<Integer> tiles,
            final int[] cycles, final String ext) {
        if (!parentDir.exists()) {
            if (!parentDir.mkdir()) {
                throw new RuntimeException("Couldn't create directory " + parentDir.getAbsolutePath());
            }
        }

        for (final int cycle : cycles) {
            final File cycleDir = new File(parentDir, "C" + cycle + ".1");
            if (!cycleDir.exists()) {
                if (!cycleDir.mkdir()) {
                    throw new RuntimeException("Couldn't create directory " + cycleDir.getAbsolutePath());
                }
            }

            for (final Integer tile : tiles) {
                writeNonEmptyFile(new File(cycleDir, "s_" + lane + "_" + tile + ext));
            }
        }
    }

    private static void writeNonEmptyFile(final File file) {
        try {
            final OutputStream outputStream = new DataOutputStream(new FileOutputStream(file));
            final int expectedLength = 10;
            outputStream.write(expectedLength);
            // The negative beginning index is to accommodate the header. Fancy. Ever so fancy.
            for (int i = -3; i < expectedLength; i++)
                outputStream.write(0x0);
            outputStream.close();
        } catch (final IOException e) {
            throw new RuntimeException("Exception trying to create non-empty file!", e);
        }
    }
}