Search in sources :

Example 1 with PartialEntity

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));
    }
}
Also used : PartialEntity(io.milton.http.entity.PartialEntity) FileOutputStream(java.io.FileOutputStream) Range(io.milton.http.Range) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

Range (io.milton.http.Range)1 PartialEntity (io.milton.http.entity.PartialEntity)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1