logger.debug("Output dir [" + OUTPUT_FILE_DIR + "] does not exist");
logger.debug("Creating output dir [" + OUTPUT_FILE_DIR + "] ...");
if(outputDir.mkdirs()) {
logger.debug("Output dir [" + OUTPUT_FILE_DIR + "] succesfully created");
} else {
throw new SpagoBIRuntimeException("Impossible to create outputd dir [" + OUTPUT_FILE_DIR + "]");
}
} else {
if(!outputDir.isDirectory()) {
throw new SpagoBIRuntimeException("Outputd dir [" + OUTPUT_FILE_DIR + "] i not a valid directory");
}
}
if(outputFile.exists()) {
logger.debug("Output file [" + outputFile.getName() + "] alredy exists. It wil be overwritten");
}
try {
out = new BufferedOutputStream(new FileOutputStream(outputFile));
} catch (FileNotFoundException e) {
throw new SpagoBIRuntimeException("Impossible to open a byte stream to file [" + outputFile.getName() + "]", e);
}
Assert.assertNotNull(out, "Output stream cannot be null");
try {
out.write(content);
} catch (IOException e) {
throw new SpagoBIRuntimeException("Impossible to write on file [" + outputFile.getName() + "]", e);
}
} catch(Throwable t) {
throw new SpagoBIRuntimeException("An unpredicted error occurs while saving document to file [" + outputFile.getName() + "]", t);
} finally {
if(out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
throw new SpagoBIRuntimeException("Impossible to properly close file [" + outputFile.getName() + "]", e);
}
}
logger.debug("OUT");
}