use of org.exist.util.io.CloseNotifyingOutputStream in project exist by eXist-db.
the class EmbeddedOutputStream method openStream.
private static Either<IOException, OutputStream> openStream(final BrokerPool pool, final XmldbURL url) {
if (LOG.isDebugEnabled()) {
LOG.debug("Begin document download");
}
try {
// get a temporary file
final TemporaryFileManager tempFileManager = TemporaryFileManager.getInstance();
final Path tempFile = tempFileManager.getTemporaryFile();
final OutputStream osTemp = new BufferedOutputStream(Files.newOutputStream(tempFile, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE));
// upload the content of the temp file to the db when it is closed, then return the temp file
final RunnableE<IOException> uploadOnClose = () -> {
uploadToDb(pool, url, tempFile);
tempFileManager.returnTemporaryFile(tempFile);
};
return Right(new CloseNotifyingOutputStream(osTemp, uploadOnClose));
} catch (final IOException e) {
return Left(e);
}
}
Aggregations