{
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
String tempName = getTempFileName(entryName);
TempStore store = (context != null) ? context.getTempStore() : null;
if (store != null)
{
File tempDir = store.createTempFolder(zipSource.getName(), ent.getName());
if (tempDir != null)
dest = new File(tempDir, tempName);
}
if (dest == null)
dest = new File(getTempDir() + "/" + tempName);
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(new DefaultZipEntryInfo(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(new DefaultZipEntryInfo(ent)));
}
entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
addChild(parent, delegator);
}
else
{
ZipEntryHandler wrapper = new ZipEntryHandler(this, parent, name, ent.isDirectory() == false);