}
// make sure we are allowed to save this file
RollerMessages msgs = new RollerMessages();
if (!canSave(weblog, savePath, contentType, size, msgs)) {
throw new FileIOException(msgs.toString());
}
// make sure uploads area exists for this weblog
File dirPath = this.getRealFile(weblog, null);
File saveFile = new File(dirPath.getAbsolutePath() + File.separator + savePath);
byte[] buffer = new byte[8192];
int bytesRead = 0;
OutputStream bos = null;
try {
bos = new FileOutputStream(saveFile);
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
log.debug("The file has been written to ["+saveFile.getAbsolutePath()+"]");
} catch (Exception e) {
throw new FileIOException("ERROR uploading file", e);
} finally {
try {
bos.flush();
bos.close();
} catch (Exception ignored) {}