else {
earFileName = null;
}
WriteStream archiveStream = null;
ZipInputStream zipInputStream = null;
ZipOutputStream zipOutputStream = null;
try {
archiveStream = archivePath.openWrite();
zipOutputStream = new ZipOutputStream(archiveStream);
zipInputStream = new ZipInputStream(archiveIs);
ZipEntry zipEntry = zipInputStream.getNextEntry();
TreeSet<String> entryNames = new TreeSet<String>();
int copyCount = 0;
while (zipEntry != null) {
if (log.isLoggable(Level.FINEST))
log.log(Level.FINEST, L.l("jsr88 copying entry {0}", zipEntry));
entryNames.add(zipEntry.getName());
zipOutputStream.putNextEntry(zipEntry);
try {
for (int ch = zipInputStream.read(); ch != -1; ch = zipInputStream.read())
zipOutputStream.write(ch);
} catch (IOException e) {
// XXX: unexpected end of ZLIB input stream.
log.log(Level.WARNING, L.l("exception copying entry {0}", zipEntry), e);
}
zipEntry = zipInputStream.getNextEntry();
copyCount++;
}
if (log.isLoggable(Level.FINER))
log.log(Level.FINER, L.l("copied {0} entries", copyCount));
if (archiveIs.read() != -1) {
if (log.isLoggable(Level.FINE))
log.log(Level.FINE, L.l("unexpected data at end of archive"));
while (archiveIs.read() != -1) {}
}
int fileCount = 0;
for (DeploymentPlan.PlanFile file : plan.getFileList()) {
String zipEntryName = file.getPath();
if (zipEntryName.startsWith("/"))
zipEntryName = zipEntryName.substring(1);
if (log.isLoggable(Level.FINEST))
log.log(Level.FINEST, L.l("jsr88 plan file {0} output to {1}", file, zipEntryName));
if (entryNames.contains(zipEntryName))
log.log(Level.WARNING, L.l("plan file {0} overwrites existing file", zipEntryName));
entryNames.add(zipEntryName);
zipEntry = new ZipEntry(zipEntryName);
zipOutputStream.putNextEntry(zipEntry);
file.writeToStream(zipOutputStream);
fileCount++;
}
if (log.isLoggable(Level.FINER))
log.log(Level.FINER, L.l("created {0} entries from plan", fileCount));
zipInputStream.close();
zipInputStream = null;
zipOutputStream.close();
zipOutputStream = null;
archiveStream.close();
archiveStream = null;
}
finally {
if (zipInputStream != null) {
try {
zipInputStream.close();
}
catch (Exception ex) {
log.log(Level.FINER, ex.toString(), ex);
}
}