//the unique file does not exist. maybe first run?
report.reportDebugLog("localhost", "The unique file is missing, creating a new one: " + uniqueFile.getAbsolutePath());
try {
if(!uniqueFile.createNewFile()){
report.reportErrorLog("localhost","Unable to create the unique file.");
throw new UniqueFileException("Unable to create the unique file.");
} else {
return;
}
} catch (IOException e) {
report.reportVerbouseLog("locahost", e.getMessage());
throw new UniqueFileException("IOException hit while creating the unique file.");
}
}
if(!uniqueFile.canRead()){
report.reportErrorLog("localhost", "Unable to read the unique file: "
+ uniqueFile.getAbsolutePath());
throw new UniqueFileException("Unique file not readable.");
}
if(!uniqueFile.canWrite()){
report.reportErrorLog("localhost", "Unable to write to the unique file: "
+ uniqueFile.getAbsolutePath());
throw new UniqueFileException("Unique file not writable.");
}
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(uniqueFile));
if(!br.ready()){
report.reportErrorLog("localhost", "It seems that the unique file is empty: "
+ uniqueFile.getAbsolutePath());
throw new UniqueFileException(String.format("Unique file %s not readable.", uniqueFile.getAbsolutePath()));
}
unique = Integer.parseInt(br.readLine());
} catch (FileNotFoundException e) {
report.reportErrorLog("localhost", "The unique file was not found: "
+ uniqueFile.getAbsolutePath());
throw new UniqueFileException("The Unique file could not be found.");
} catch (IOException e){
report.reportErrorLog("localhost", "IOException hit while reading the unique file: "
+ uniqueFile.getAbsolutePath());
throw new UniqueFileException("IOException hit while reading the unique file.");
} catch (NumberFormatException e){
report.reportErrorLog("localhost", "The first line of the unique file is not a parsable integer: "
+ uniqueFile.getAbsolutePath());
throw new ConfigurationUnacceptableValue("The first line of the unique file is not a parsable integer.");
}