Path tempDir = _rootDir.getParent().lookup(".temp");
Path dependPath = _rootDir.lookup("META-INF/resin-rar.timestamp");
// XXX: change to a hash
if (dependPath.canRead()) {
ReadStream is = null;
ObjectInputStream ois = null;
try {
is = dependPath.openRead();
ois = new ObjectInputStream(is);
long lastModified = ois.readLong();
long length = ois.readLong();
if (lastModified == rar.getLastModified() &&
length == rar.getLength())
return;
} catch (IOException e) {
} finally {
try {
if (ois != null)
ois.close();
} catch (IOException e) {
}
if (is != null)
is.close();
}
}
try {
if (log.isLoggable(Level.INFO))
log.info("expanding rar " + rar + " to " + tempDir);
if (! tempDir.equals(expandDir)) {
tempDir.removeAll();
}
tempDir.mkdirs();
ReadStream rs = rar.openRead();
ZipInputStream zis = new ZipInputStream(rs);
try {
ZipEntry entry;
byte []buffer = new byte[1024];
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
Path path = tempDir.lookup(name);
if (entry.isDirectory())
path.mkdirs();
else {
long length = entry.getSize();
long lastModified = entry.getTime();
path.getParent().mkdirs();
WriteStream os = path.openWrite();
try {
int len;
while ((len = zis.read(buffer, 0, buffer.length)) > 0)
os.write(buffer, 0, len);
} catch (IOException e) {
log.log(Level.FINE, e.toString(), e);
} finally {
os.close();
}
if (lastModified > 0)
path.setLastModified(lastModified);
}
}
} finally {
try {
zis.close();
} catch (IOException e) {
}
rs.close();
}
if (! tempDir.equals(expandDir)) {
if (log.isLoggable(Level.INFO))
log.info("moving rar " + rar + " to " + expandDir);