try {
if (!restarted) {
if (!append) {
if (file.exists()) {
if (!overwriteOutputFile) {
throw new ItemStreamException("File already exists: [" + file.getAbsolutePath() + "]");
}
if (!file.delete()) {
throw new IOException("Could not delete file: " + file);
}
}
if (file.getParent() != null) {
new File(file.getParent()).mkdirs();
}
if (!createNewFile(file)) {
throw new ItemStreamException("Output file was not created: [" + file.getAbsolutePath() + "]");
}
}
else {
if (!file.exists()) {
if (file.getParent() != null) {
new File(file.getParent()).mkdirs();
}
if (!createNewFile(file)) {
throw new ItemStreamException("Output file was not created: [" + file.getAbsolutePath()
+ "]");
}
}
}
}
}
catch (IOException ioe) {
throw new ItemStreamException("Unable to create file: [" + file.getAbsolutePath() + "]", ioe);
}
if (!file.canWrite()) {
throw new ItemStreamException("File is not writable: [" + file.getAbsolutePath() + "]");
}
}