use of io.milton.http.entity.PartialEntity in project lobcder by skoulouzis.
the class PartialGetHelper method sendPartialContent.
public void sendPartialContent(GetableResource resource, Request request, Response response, List<Range> ranges, Map<String, String> params) throws NotAuthorizedException, BadRequestException, IOException, NotFoundException {
log.trace("sendPartialContent");
if (ranges.size() == 1) {
log.trace("partial get, single range");
Range r = ranges.get(0);
responseHandler.respondPartialContent(resource, response, request, params, r);
} else {
log.trace("partial get, multiple ranges");
File temp = File.createTempFile("milton_partial_get", null);
FileOutputStream fout = null;
try {
fout = new FileOutputStream(temp);
BufferedOutputStream bufOut = new BufferedOutputStream(fout);
resource.sendContent(bufOut, null, params, request.getContentTypeHeader());
bufOut.flush();
fout.flush();
} finally {
StreamUtils.close(fout);
}
response.setEntity(new PartialEntity(ranges, temp));
}
}
Aggregations