public static FsEntry createElement(FsFolder parent, File file) { FsEntry element; if (file.isDirectory()) { element = FsFolder.createFolder(parent, file); } else { String filename = file.getName(); int idx = filename.lastIndexOf('.'); String ext = (idx == -1) ? null : filename.substring(idx + 1); boolean zipped = "zip".equals(ext) || "jar".equals(ext); element = zipped ? FsFolder.createFolder(parent, file) : FsFile.createFile(parent, file); } return element; }
public FsEntry getInstance(FsFolder parent, ZipEntry subEntry) { FsEntry elem = null; if (_zipfile != null) { elem = parent.getInstance(_zipfile, subEntry); } else if (_url != null) { elem = parent.getInstance(null, subEntry); // elem = parent.getInstance(_url, subEntry); } else { elem = null; } return elem; }
private File createTemporaryFile(FsFolder folderRef, ZipFile zipfile, ZipEntry entry) throws IOException { String prefix = entry.getName(); int len = prefix.length(); Enumeration<? extends ZipEntry> enu = zipfile.entries(); while (enu.hasMoreElements()) { ZipEntry e = enu.nextElement(); String name = e.getName(); if (!name.equals(prefix) && name.startsWith(prefix)) { String suffix = name.substring(len); File file = new File(folderRef.m_file, suffix); if (e.isDirectory()) { file.mkdirs(); } else { file.createNewFile(); InputStream input = zipfile.getInputStream(entry); unzipTo(input, file); } } } // end while List<FsEntry> elements = folderRef.getFolderElements(); String entryname = entry.getName(); String resourceURL = "jar:file:" + zipfile.getName() + "!/" + entryname; File tmlFile = JarUtil.createTemporaryFile(resourceURL); return tmlFile; }
// resource can be a URL or a folder public static FsFolder createRoot(String resource) { FsFolder root = null; // is it a URL? try { URL url = new URL(resource); root = FsFolder.createRoot(url); } catch (MalformedURLException ex) { // no, it is a file? File file = new File(resource); if (file.exists() && file.isDirectory()) { root = FsFolder.createRoot(file); } } // end try return root; }
// // private constructors // private FsFolder(FsFolder parent, File file) { if (parent != null) { String name = file.getName(); parent.addChild(name, this); m_parent = parent; } m_file = file; // buildChildren(); }
public FsEntry getNamedDescendent(String resourceName) { FsEntry namedChild = null; FsFolder folder = this; boolean directory = resourceName.endsWith("/"); StringTokenizer st = new StringTokenizer(resourceName, "/"); while (st.hasMoreTokens()) { String name = st.nextToken(); if (st.hasMoreTokens() || directory) { name += "/"; } namedChild = folder.getNamedChild(name); if (namedChild instanceof FsFolder) { folder = (FsFolder) namedChild; } } return namedChild; }
private FsFolder( FsFolder parent, String folderName, ZipFileAndURLUnion composite, ZipEntry entry) { if (parent != null) { parent.addChild(folderName, this); m_parent = parent; } // parent.addChild(folderName, folder); //important m_composite = composite; m_entry = entry; // buildChildren(); }
@Override public void copyTo(FsFolder destFolder) throws IOException { // copy = null; // create file if (m_file != null) { // String foldername = m_file.getName(); // File target = new File(destFolder.m_file, foldername); // copy = createFolder(destFolder, destFolder.m_file); List<FsEntry> elements = getFolderElements(); for (FsEntry element : elements) { String foldername = element.getSimpleName(); File destParent = destFolder.m_file; File newFile = new File(destParent, foldername); if (element instanceof FsFolder) { FsFolder copy = createFolder(destFolder, newFile); element.copyTo(copy); } else { // FileRef copy = FileRef.createFile(destFolder, newFile); element.copyTo(destFolder); } } } else if (m_composite != null) { // create folder String entryName = m_entry.getName(); int len = entryName.length(); int idx = entryName.lastIndexOf('/', len - 2); String suffix = entryName.substring(idx + 1, len - 1); File folder = new File(destFolder.m_file, suffix); folder.mkdirs(); FsFolder copy = FsFolder.createFolder(destFolder, folder); // unzip in folder List<FsEntry> entries = getFolderElements(); for (FsEntry entry : entries) { entry.copyTo(copy); } // unzipEntries(folderRef); // new ZipInputStream(); /* File f = createTemporaryFile(folderRef, m_zipfile, m_entry); f.createNewFile(); FileRef tempfile = FileRef.createFile(destFolder, f); */ } }
public static FsFolder createFolder(FsFolder parent, File folder) { FsFolder folderRef = (FsFolder) parent.getInstance(folder); if (folderRef == null) { if (!folder.exists()) { folder.mkdirs(); } folderRef = new FsFolder(parent, folder); String name = folder.getName(); // parent.addChild(name, folderRef); } return folderRef; }
private static FsFolder createFolder( FsFolder parent, String foldername, ZipFileAndURLUnion composite, ZipEntry entry) { FsFolder element = FsFolder.createFolder(parent, foldername, composite, entry); return element; }
public static FsEntry createElement( FsFolder parent, ZipFileAndURLUnion composite, ZipEntry entry) { FsEntry element = null; String prefix = parent.getQualifiedName(); boolean directory = entry.isDirectory(); String entryName = entry.getName(); if (entryName.startsWith(prefix)) { String subEntryName = prefix; String suffix = entryName.substring(prefix.length()); StringTokenizer st = new StringTokenizer(suffix, "/"); while (st.hasMoreTokens()) { String token = st.nextToken(); String elementName = (st.hasMoreTokens() || directory) ? (token + "/") : token; subEntryName += elementName; if (st.hasMoreTokens()) { ZipEntry subEntry = composite.getEntry(subEntryName); if (subEntry == null) { int i = 0; i++; } FsEntry elem = composite.getInstance(parent, subEntry); if (elem == null) { elem = createFolder(parent, subEntryName, composite, subEntry); } if (elem instanceof FsFolder) { parent = (FsFolder) elem; } } else { // boolean directory = entry.isDirectory(); element = directory ? createFolder(parent, elementName, composite, entry) : FsFile.createFile(parent, elementName, composite, entry); } } } else { String subEntryName = ""; ; StringTokenizer st = new StringTokenizer(entryName, "/"); while (st.hasMoreTokens()) { String token = st.nextToken(); String elementName = (st.hasMoreTokens() || directory) ? (token + "/") : token; subEntryName += elementName; if (st.hasMoreTokens()) { ZipEntry subEntry = composite.getEntry(subEntryName); FsEntry elem = composite.getInstance(parent, subEntry); if (elem == null) { elem = createFolder(parent, subEntryName, composite, subEntry); } if (elem instanceof FsFolder) { parent = (FsFolder) elem; } } else { // boolean directory = entry.isDirectory(); element = directory ? createFolder(parent, elementName, composite, entry) : FsFile.createFile(parent, elementName, composite, entry); } } // end while } return element; }