本文整理汇总了Java中de.fuberlin.wiwiss.d2rq.download.DownloadContentQuery类的典型用法代码示例。如果您正苦于以下问题:Java DownloadContentQuery类的具体用法?Java DownloadContentQuery怎么用?Java DownloadContentQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DownloadContentQuery类属于de.fuberlin.wiwiss.d2rq.download包,在下文中一共展示了DownloadContentQuery类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleDownload
import de.fuberlin.wiwiss.d2rq.download.DownloadContentQuery; //导入依赖的package包/类
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;
}