Search in sources :

Example 1 with Result

use of org.expath.httpclient.model.Result in project exist by eXist-db.

the class EXistResult method add.

@Override
public void add(final InputStream is) throws HttpClientException {
    try {
        // we have to make a temporary copy of the data stream, as the socket will be closed shortly
        final TemporaryFileManager temporaryFileManager = TemporaryFileManager.getInstance();
        final Path tempFile = temporaryFileManager.getTemporaryFile();
        Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING);
        result.add(BinaryValueFromFile.getInstance(context, new Base64BinaryValueType(), tempFile, (isClosed, file) -> temporaryFileManager.returnTemporaryFile(file)));
    } catch (final XPathException | IOException xpe) {
        throw new HttpClientException("Unable to add binary value to result:" + xpe.getMessage(), xpe);
    } finally {
        try {
            is.close();
        } catch (final IOException ioe) {
            logger.warn(ioe.getMessage(), ioe);
        }
    }
}
Also used : Path(java.nio.file.Path) TypeTest(org.exist.xquery.TypeTest) Files(java.nio.file.Files) TemporaryFileManager(org.exist.util.io.TemporaryFileManager) Result(org.expath.httpclient.model.Result) org.exist.xquery.value(org.exist.xquery.value) IOException(java.io.IOException) Reader(java.io.Reader) Source(javax.xml.transform.Source) StandardCopyOption(java.nio.file.StandardCopyOption) HttpResponse(org.expath.httpclient.HttpResponse) Logger(org.apache.logging.log4j.Logger) Charset(java.nio.charset.Charset) ModuleUtils(org.exist.xquery.modules.ModuleUtils) HttpClientException(org.expath.httpclient.HttpClientException) SAXException(org.xml.sax.SAXException) NodeTest(org.exist.xquery.NodeTest) DocumentImpl(org.exist.dom.memtree.DocumentImpl) Path(java.nio.file.Path) LogManager(org.apache.logging.log4j.LogManager) XPathException(org.exist.xquery.XPathException) XQueryContext(org.exist.xquery.XQueryContext) InputStream(java.io.InputStream) HttpClientException(org.expath.httpclient.HttpClientException) XPathException(org.exist.xquery.XPathException) IOException(java.io.IOException) TemporaryFileManager(org.exist.util.io.TemporaryFileManager)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 Source (javax.xml.transform.Source)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 DocumentImpl (org.exist.dom.memtree.DocumentImpl)1 TemporaryFileManager (org.exist.util.io.TemporaryFileManager)1 NodeTest (org.exist.xquery.NodeTest)1 TypeTest (org.exist.xquery.TypeTest)1 XPathException (org.exist.xquery.XPathException)1 XQueryContext (org.exist.xquery.XQueryContext)1 ModuleUtils (org.exist.xquery.modules.ModuleUtils)1 org.exist.xquery.value (org.exist.xquery.value)1 HttpClientException (org.expath.httpclient.HttpClientException)1 HttpResponse (org.expath.httpclient.HttpResponse)1