int total = 0;
int threshold = 10240;
URLConnection uc = url.openConnection();
int filesize = uc.getContentLength();
InputStream net = uc.getInputStream();
JarFile jar = null;
File download = null;
try {
download = File.createTempFile("geronimo-driver-download", ".zip");
OutputStream out = new BufferedOutputStream(new FileOutputStream(download));
if (monitor != null) {
monitor.writeStarted("Download driver archive to " + download, filesize);
}
try {
while ((size = net.read(buf)) > -1) {
out.write(buf, 0, size);
if (monitor != null) {
total += size;
if (total > threshold) {
monitor.writeProgress(total);
threshold += 10240;
}
}
}
out.flush();
out.close();
} finally {
if (monitor != null) {
monitor.writeComplete(total);
}
}
jar = new JarFile(download);
JarEntry entry = jar.getJarEntry(driver.unzipPath);
if (entry == null) {
log.error("Cannot extract driver JAR " + driver.unzipPath + " from download file " + url);
} else {
in = jar.getInputStream(entry);
repo.copyToRepository(in, (int)entry.getSize(), Artifact.create(uri), monitor);
}
} finally {
if (jar != null) try {
jar.close();
} catch (IOException e) {
log.error("Unable to close JAR file", e);
}
if (download != null) {
download.delete();