response.setDateHeader("Expires", System.currentTimeMillis()
+ expires);
response.setHeader("Content-disposition","attachement; filename=" + this.compressedExportName );
ByteRange byteRange = null;
// Turn off partial downloads, they cause problems
// and are only rarely used. Specifically some windows pdf
// viewers are incapable of handling this request. You can
// uncomment the following lines to turn this feature back on.
// response.setHeader("Accept-Ranges", "bytes");
// String ranges = request.getHeader("Range");
// if (ranges != null)
// {
// try
// {
// ranges = ranges.substring(ranges.indexOf('=') + 1);
// byteRange = new ByteRange(ranges);
// }
// catch (NumberFormatException e)
// {
// byteRange = null;
// if (response instanceof HttpResponse)
// {
// // Respond with status 416 (Request range not
// // satisfiable)
// response.setStatus(416);
// }
// }
// }
if (byteRange != null)
{
String entityLength;
String entityRange;
if (this.compressedExportSize != -1)
{
entityLength = "" + this.compressedExportSize;
entityRange = byteRange.intersection(
new ByteRange(0, this.compressedExportSize)).toString();
}
else
{
entityLength = "*";
entityRange = byteRange.toString();
}
response.setHeader("Content-Range", entityRange + "/"
+ entityLength);
if (response instanceof HttpResponse)
{
// Response with status 206 (Partial content)
((HttpResponse) response).setStatus(206);
}
int pos = 0;
int posEnd;
while ((length = this.compressedExportInputStream.read(buffer)) > -1)
{
posEnd = pos + length - 1;
ByteRange intersection = byteRange
.intersection(new ByteRange(pos, posEnd));
if (intersection != null)
{
out.write(buffer, (int) intersection.getStart()
- pos, (int) intersection.length());
}
pos += length;
}
}
else