{
boolean useCopyMode = forceCopy;
if (useCopyMode == false)
useCopyMode = getAggregatedOptions().getBooleanOption(VFSUtils.USE_COPY_QUERY);
DelegatingHandler delegator;
if (useCopyMode)
{
File dest = null;
String entryName = ent.getName();
String path = null;
VFSContext context = getPeerContext();
if (context != null)
{
path = getPath(context, entryName);
TempInfo ti = context.getTempInfo(path);
if (ti != null && ti.isValid())
{
dest = ti.getTempFile();
}
}
boolean createNewTempInfo = (dest == null || dest.exists() == false);
if (createNewTempInfo)
{
// extract it to temp dir
dest = new File(getTempDir() + "/" + getTempFileName(entryName));
dest.deleteOnExit();
if (trace)
{
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
log.trace("Dest: " + dest + ", Stack-trace:\n" + Arrays.toString(stackTraceElements));
}
// ensure parent exists
dest.getParentFile().mkdirs();
InputStream is = zipSource.openStream(ent);
OutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
VFSUtils.copyStreamAndClose(is, os);
}
// mount another instance of ZipEntryContext
delegator = mountZipFile(parent, name, dest);
if (context != null && path != null && createNewTempInfo)
context.addTempInfo(new ZipEntryTempInfo(path, dest, delegator, this));
}
else
{
// mount another instance of ZipEntryContext
delegator = mountZipStream(parent, name, zipSource.openStream(ent));
}
entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
addChild(parent, delegator);
}
else
{
ZipEntryHandler wrapper = new ZipEntryHandler(this, parent, name, ent.isDirectory() == false);