in remoting/server/web/nbindex.web.api/src/org/netbeans/modules/jackpot30/backend/usages/api/DownloadableIndex.java [74:135]
public Response index(@QueryParam("path") String segment) throws IOException, InterruptedException {
CategoryStorage category = CategoryStorage.forId(segment);
final FileObject idxRoot = category.getCacheRoot();
if (idxRoot == null || !idxRoot.canRead()) return Response.status(Response.Status.NOT_FOUND).build();
long totalSize = 0;
for (String rel : PARTS_TO_COPY) {
FileObject relFO = idxRoot.getFileObject(rel);
if (relFO == null) continue;
Iterable<? extends FileObject> children;
if (relFO.isFolder()) children = NbCollections.iterable(relFO.getChildren(true));
else children = Collections.singletonList(relFO);
for (FileObject c : children) {
if (c.isFolder()) continue;
totalSize += c.getSize();
}
}
return Response.ok().header("NB-Total-Unpacked-Size", String.valueOf(totalSize)).entity(new StreamingOutput() {
@Override public void write(OutputStream output) throws IOException, WebApplicationException {
JarOutputStream out = new JarOutputStream(output);
try {
for (String rel : PARTS_TO_COPY) {
FileObject relFO = idxRoot.getFileObject(rel);
if (relFO == null) continue;
Iterable<? extends FileObject> children;
if (relFO.isFolder()) children = NbCollections.iterable(relFO.getChildren(true));
else children = Collections.singletonList(relFO);
for (FileObject c : children) {
if (c.isFolder()) continue;
out.putNextEntry(new ZipEntry(FileUtil.getRelativePath(idxRoot, c)));
InputStream in = c.getInputStream();
try {
FileUtil.copy(in, out);
} finally {
in.close();
}
out.closeEntry();
}
}
} finally {
out.close();
}
}
} ).build();
}