public Reader() { File indexFile = getIndexFile(); File outputsFile = getOutputsFile(); if (outputsFile.exists()) { if (!indexFile.exists()) { throw new IllegalStateException( String.format( "Test outputs data file '%s' exists but the index file '%s' does not", outputsFile, indexFile)); } Input input; try { input = new Input(new FileInputStream(indexFile)); } catch (FileNotFoundException e) { throw new UncheckedIOException(e); } IndexBuilder rootBuilder = null; try { int numClasses = input.readInt(true); rootBuilder = new IndexBuilder(); for (int classCounter = 0; classCounter < numClasses; ++classCounter) { long classId = input.readLong(true); IndexBuilder classBuilder = new IndexBuilder(); int numEntries = input.readInt(true); for (int entryCounter = 0; entryCounter < numEntries; ++entryCounter) { long testId = input.readLong(true); Region stdOut = new Region(input.readLong(), input.readLong()); Region stdErr = new Region(input.readLong(), input.readLong()); classBuilder.add(testId, new Index(stdOut, stdErr)); } rootBuilder.add(classId, classBuilder.build()); } } finally { input.close(); } index = rootBuilder.build(); try { dataFile = new RandomAccessFile(getOutputsFile(), "r"); } catch (FileNotFoundException e) { throw new UncheckedIOException(e); } } else { // no outputs file if (indexFile.exists()) { throw new IllegalStateException( String.format( "Test outputs data file '{}' does not exist but the index file '{}' does", outputsFile, indexFile)); } index = null; dataFile = null; } }