/** * Wow, this is hard to understand... * * @param inZip -- The Zip InputStream entries have paths buried in them e.g., * data/subdir/file.txt * @param inDest -- The destination folder, e.g. /opt/appserver/webapp/ROOT * @param inPathSegment -- A path segment that might exist in the Zip entries, e.g. /data or data * @param inNewPathSegment -- A new path segment we want to use, e.g. /backup to make * backup/subdir/file.txt * @throws IOException */ public List unzip(InputStream inZip, File inDest, String inCutOffLeadingPath) throws IOException { ZipInputStream unzip = new ZipInputStream(inZip); ZipEntry entry = unzip.getNextEntry(); List unzippedFiles = new ArrayList(); while (entry != null) { String entryPath = composeEntryPath(entry.getName(), inCutOffLeadingPath); if (fieldFindFileName != null) { if (!PathUtilities.match(entry.getName(), fieldFindFileName)) // TODO // : // Handle // leading // / { entry = unzip.getNextEntry(); continue; } } if (entryPath.contains("__MACOSX")) { entry = unzip.getNextEntry(); continue; } // int zipeSize = (int) entry.getSize(); if (!entry.isDirectory()) { File ufile = null; if (inDest != null) { ufile = new File(inDest, entryPath); } else { ufile = new File(entryPath); } ufile.getParentFile().mkdirs(); if (ufile.exists() && !ufile.delete()) { getWindowsUtil().delete(ufile); } FileOutputStream tout = new FileOutputStream(ufile); try { filler.fill(unzip, tout); } finally { FileUtils.safeClose(tout); } ufile.setLastModified(entry.getTime()); if (log.isDebugEnabled()) { log.debug(ufile.getAbsolutePath()); } unzippedFiles.add(ufile); if (isExitOnFirstFind()) { return unzippedFiles; } } entry = unzip.getNextEntry(); } return unzippedFiles; }
protected boolean exclude(String inOpenEditPath) { if (fieldExcludes != null) { for (Iterator iter = getExcludes().iterator(); iter.hasNext(); ) { String wild = (String) iter.next(); if (PathUtilities.match(inOpenEditPath, wild)) { return true; } } } return false; }
public static void guaranteePathReader() { IPathReader reader = PathUtilities.getReader(); // todo this works but might not in the cluster if (reader == null) throw new UnsupportedOperationException("Add a Sparky reader"); }