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);
}
}
}
Aggregations