parent.mkdirs();
} catch (Throwable e) {
}
Path dependPath = expandDir.lookup("META-INF/resin-war.digest");
Depend depend = null;
// XXX: change to a hash
if (dependPath.canRead()) {
ReadStream is = null;
try {
is = dependPath.openRead();
String line = is.readLine();
long digest;
if (line != null) {
digest = Long.parseLong(line.trim());
depend = new Depend(archivePath, digest);
if (! depend.isModified())
return true;
}
} catch (Throwable e) {
log.log(Level.FINE, e.toString(), e);
} finally {
if (is != null)
is.close();
}
}
if (depend == null)
depend = new Depend(archivePath);
try {
if (log.isLoggable(Level.INFO))
getLog().info("expanding " + archivePath + " to " + expandDir);
removeExpandDirectory(expandDir);
expandDir.mkdirs();
ReadStream rs = archivePath.openRead();
ZipInputStream zis = new ZipInputStream(rs);
try {
ZipEntry entry = zis.getNextEntry();
byte []buffer = new byte[1024];
while (entry != null) {
String name = entry.getName();
Path path = expandDir.lookup(name);
if (entry.isDirectory())
path.mkdirs();
else {
long entryLength = entry.getSize();
long length = entryLength;
// XXX: avoids unexpected end of ZLIB input stream.
// XXX: This should be a really temp. workaround.
int bufferLen = buffer.length;
// XXX: avoids unexpected end of ZLIB input stream.
if (length < 0) {
// bufferLen = 1;
length = Long.MAX_VALUE / 2;
}
else if (length < bufferLen) {
bufferLen = (int) length;
}
long lastModified = entry.getTime();
path.getParent().mkdirs();
WriteStream os = path.openWrite();
int len = 0;
try {
if (bufferLen == 1) {
for (int ch = zis.read(); ch != -1; ch = zis.read())
os.write(ch);
}
else {
while ((len = zis.read(buffer, 0, bufferLen)) > 0) {
os.write(buffer, 0, len);
// XXX: avoids unexpected end of ZLIB input stream.
/*
if (len < bufferLen) {
for (int ch = zis.read(); ch != -1; ch = zis.read())
os.write(ch);
break;
}
*/
length -= len;
if (length < bufferLen) {
bufferLen = (int) length;
}
}
}
} catch (IOException e) {
Exception ex = new Exception("IOException when expanding entry "+entry+" in "+archivePath+", entry.length: "+entryLength+" entry.compressed: "+entry.getCompressedSize()+", bufferLen: "+bufferLen+", read len: "+len+", remaining: "+length,e);
log.log(Level.FINE, ex.toString(), ex);
} finally {
os.close();
}
if (lastModified > 0)
path.setLastModified(lastModified);
}
try {
entry = zis.getNextEntry();
} catch (IOException e) {
log.log(Level.FINE, e.toString(), e);
// XXX: avoids unexpected end of ZLIB input stream.
break;
}
}
} finally {
try {
zis.close();
} catch (IOException e) {
}
rs.close();
}
} catch (IOException e) {
log.log(Level.WARNING, e.toString(), e);
// If the jar is incomplete, it should throw an exception here.
return false;
}
try {
dependPath.getParent().mkdirs();
WriteStream os = dependPath.openWrite();
os.println(depend.getDigest());
os.close();
} catch (Throwable e) {
log.log(Level.WARNING, e.toString(), e);
}