private void initializeBufferedWriter() {
File file;
try {
file = resource.getFile();
// If the output source was restarted, keep existing file.
// If the output source was not restarted, check following:
// - if the file should be deleted, delete it if it was exiting
// and create blank file,
// - if the file should not be deleted, if it already exists,
// throw an exception,
// - if the file was not existing, create new.
if (!restarted) {
if (file.exists()) {
if (shouldDeleteIfExists) {
file.delete();
} else {
throw new ItemStreamException("Resource already exists: " + resource);
}
}
String parent = file.getParent();
if (parent != null) {
new File(parent).mkdirs();
}
file.createNewFile();
}