private boolean handleDownload(String resourceURI, HttpServletResponse response, D2RServer server) throws IOException {
Mapping m = D2RServer.retrieveSystemLoader(getServletContext()).getMapping();
for (Resource r: m.downloadMapResources()) {
DownloadMap d = m.downloadMap(r);
DownloadContentQuery q = new DownloadContentQuery(d, resourceURI);
if (q.hasContent()) {
response.setContentType(q.getMediaType() != null ? q.getMediaType() : "application/octet-stream");
InputStream is = q.getContentStream();
OutputStream os = response.getOutputStream();
final byte[] buffer = new byte[0x10000];
int read;
do {
read = is.read(buffer, 0, buffer.length);
if (read>0) {
os.write(buffer, 0, read);
}
} while (read >= 0);
is.close();
q.close();
return true;
}
}
return false;
}