Search in sources :

Example 1 with CloseNotifyingOutputStream

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);
    }
}
Also used : Path(java.nio.file.Path) CloseNotifyingOutputStream(org.exist.util.io.CloseNotifyingOutputStream) CloseNotifyingOutputStream(org.exist.util.io.CloseNotifyingOutputStream) TemporaryFileManager(org.exist.util.io.TemporaryFileManager)

Aggregations

Path (java.nio.file.Path)1 CloseNotifyingOutputStream (org.exist.util.io.CloseNotifyingOutputStream)1 TemporaryFileManager (org.exist.util.io.TemporaryFileManager)1