use of javax.ws.rs.core.StreamingOutput in project ice by JBEI.
the class SampleResource method getRequestFile.
@POST
@Path("/requests/file")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getRequestFile(@QueryParam("sid") String sid, final ArrayList<Long> requestIds) {
// only supports csv for now
if (StringUtils.isEmpty(sessionId))
sessionId = sid;
final String userId = getUserId(sessionId);
final ArrayList<Long> sampleRequestIds = new ArrayList<>();
for (final Number number : requestIds) {
sampleRequestIds.add(number.longValue());
}
try {
ByteArrayOutputStream outputStream = requestRetriever.generateCSVFile(userId, sampleRequestIds);
StreamingOutput stream = outputStream::writeTo;
return Response.ok(stream).header("Content-Disposition", "attachment;filename=\"data.csv\"").build();
} catch (IOException e) {
Logger.error(e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of javax.ws.rs.core.StreamingOutput in project tika by apache.
the class TikaResource method produceText.
public StreamingOutput produceText(final InputStream is, MultivaluedMap<String, String> httpHeaders, final UriInfo info) {
final Parser parser = createParser();
final Metadata metadata = new Metadata();
final ParseContext context = new ParseContext();
fillMetadata(parser, metadata, context, httpHeaders);
fillParseContext(context, httpHeaders, parser);
logRequest(LOG, info, metadata);
return new StreamingOutput() {
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(outputStream, UTF_8);
BodyContentHandler body = new BodyContentHandler(new RichTextContentHandler(writer));
parse(parser, LOG, info.getPath(), is, body, metadata, context);
}
};
}
use of javax.ws.rs.core.StreamingOutput in project tika by apache.
the class TikaResource method produceTextMain.
public StreamingOutput produceTextMain(final InputStream is, @Context MultivaluedMap<String, String> httpHeaders, @Context final UriInfo info) {
final Parser parser = createParser();
final Metadata metadata = new Metadata();
final ParseContext context = new ParseContext();
fillMetadata(parser, metadata, context, httpHeaders);
fillParseContext(context, httpHeaders, parser);
logRequest(LOG, info, metadata);
return new StreamingOutput() {
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(outputStream, UTF_8);
ContentHandler handler = new BoilerpipeContentHandler(writer);
parse(parser, LOG, info.getPath(), is, handler, metadata, context);
}
};
}
Aggregations