BufferedReader bi =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bos);
// Process the packages
String packageName;
while ((packageName = bi.readLine()) != null) {
for (PrintStream p : progress) {
p.println("Fetching meta data for " + packageName);
}
writeZipEntryForPackage(packageName, zos);
}
bi.close();
// include the package list in the zip
conn = getConnection(packageList);
ZipEntry z = new ZipEntry("packageList.txt");
BufferedInputStream bi2 = new BufferedInputStream(conn.getInputStream());
ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
transToBAOS(bi2, bos2);
zos.putNextEntry(z);
zos.write(bos2.toByteArray());
bi2.close();
// Include the top level images
String imageList = m_packageRepository.toString() + "/images.txt";
conn = getConnection(imageList);
bi = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String imageName;
while((imageName = bi.readLine()) != null) {
// System.err.println("Processing " + imageName);
z = new ZipEntry(imageName);
URLConnection conn2 = getConnection(m_packageRepository.toString()
+ "/" + imageName);
bi2 =
new BufferedInputStream(conn2.getInputStream());
bos2 = new ByteArrayOutputStream();
transToBAOS(bi2, bos2);
zos.putNextEntry(z);
zos.write(bos2.toByteArray());
bi2.close();
}
// include the image list in the zip
conn = getConnection(imageList);
z = new ZipEntry("images.txt");
bi2 = new BufferedInputStream(conn.getInputStream());
bos2 = new ByteArrayOutputStream();
transToBAOS(bi2, bos2);
zos.putNextEntry(z);
zos.write(bos2.toByteArray());
bi2.close();
zos.close();
return bos.toByteArray();
}