Search in sources :

Example 1 with SourceExtractor

use of org.icij.datashare.text.indexing.elasticsearch.SourceExtractor in project datashare by ICIJ.

the class DocumentResource method getPayload.

private Payload getPayload(Document doc, String index, boolean inline, boolean filterMetadata) throws IOException {
    try (InputStream from = new SourceExtractor(filterMetadata).getSource(project(index), doc)) {
        String contentType = ofNullable(doc.getContentType()).orElse(ContentTypes.get(doc.getPath().toFile().getName()));
        Payload payload = new Payload(contentType, InputStreams.readBytes(from));
        String fileName = doc.isRootDocument() ? doc.getName() : doc.getId().substring(0, 10) + "." + FileExtension.get(contentType);
        return inline ? payload : payload.withHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    } catch (FileNotFoundException fnf) {
        return Payload.notFound();
    }
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Payload(net.codestory.http.payload.Payload) SourceExtractor(org.icij.datashare.text.indexing.elasticsearch.SourceExtractor)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Payload (net.codestory.http.payload.Payload)1 SourceExtractor (org.icij.datashare.text.indexing.elasticsearch.SourceExtractor)1