public boolean apply(TFile tFile) { if (tFile.getName().endsWith(".class")) { ClassFile classFile = JavassistHelper.readFile(tFile); scanFile(classFile); } return true; } });
private static TFile newNonArchiveFile(TFile file) { return new TFile(file.getParentFile(), file.getName(), TArchiveDetector.NULL); }
private static TFile newNonArchiveFile(TFile file) { return new TFile(file.getParentFile(), file.getName(), TArchiveDetector.NULL); }
// append a file to archive under different name TFile.cp(new File("existingFile.txt"), new TFile("archive.zip", "entry.txt")); // recusively append a dir to the root of archive TFile src = new TFile("dirPath", "dirName"); src.cp_r(new TFile("archive.zip", src.getName()));
protected void readMeta(final ArrayList<ScreenshotMeta> metaList, final TFile[] entries) throws IOException { for (TFile file : entries) { if (file.isDirectory()) { readMeta(metaList, file.listFiles()); } else if (file.getName().endsWith(".properties")) { metaList.add(loadMeta(file)); } } }
TFile jar = new TFile("path/to/my.jar"); // a subclass of java.io.File if (jar.isDirectory()) // true for regular directories and JARs if truezip-driver-zip is on your run time class path for (TFile entry : jar.listFiles()) { // iterate top level directory if ("log4j.xml".equals(entry.getName())) { // Bingo! Now read the file or write it InputStream in = new TFileInputStream(entry); try { ... // do something here } finally { in.close(); } } else if (entry.isDirectory()) { ... // use recursion to continue searching in this directory } }
private TreePath substPath( final TreePath tp, final TreePath oldPath, final TreePath path) { final TFile file = (TFile) tp.getLastPathComponent(); if (file.equals(oldPath.getLastPathComponent())) { return path; } else { final TreePath parent = substPath(tp.getParentPath(), oldPath, path); return parent.pathByAddingChild( new de.schlichtherle.truezip.file.TFile((TFile) parent.getLastPathComponent(), file.getName())); } }
/** * Creates a file object which uses the provided TArchiveDetector, * but does not recognize its own pathname as an archive file. * Please note that this method just creates a file object, * and does not actually operate on the file system. */ private static TFile newNonArchiveFile( String path, TArchiveDetector detector) { TFile file = new TFile(path, detector); return new TFile(file.getParentFile(), file.getName(), TArchiveDetector.NULL); } }
/** * Lists the given file with the given display path. */ private void ls( final TFile file, final String path, final boolean detailed, final boolean recursive) throws IOException { if (file.isDirectory()) { final TFile[] entries = file.listFiles(); if (entries == null) throw new IOException(path + " (" + resources.getString("ls.dia") + ")"); // Sort directories to the start. Arrays.sort(entries, new TFileComparator()); for (int i = 0; i < entries.length; i++) { final TFile entry = entries[i]; final String entryPath = path.length() > 0 ? path + TFile.separator + entry.getName() : entry.getName(); ls(entry, entryPath, detailed); if (recursive && entry.isDirectory()) ls(entries[i], entryPath, detailed, true); } } else if (file.exists()) { ls(file, path, detailed); } else { throw new IOException(path + " (" + resources.getString("ls.nsfod") + ")"); } }
search(member); } else if (entry.isFile()) { if (entry.getName().endsWith(".properties"); update(entry);
private boolean isSymlink( TFile file ) throws IOException { TFile fileInCanonicalParent = null; java.io.File parentDir = file.getParentFile(); // truezip-plugin specific change if ( parentDir == null ) { fileInCanonicalParent = file; } else { fileInCanonicalParent = new TFile( parentDir.getCanonicalPath(), file.getName() ); } return !fileInCanonicalParent.getCanonicalFile().equals( fileInCanonicalParent.getAbsoluteFile() ); }
private void assertListFiles(final TFile dir, final String entry) { final TFile[] files = dir.listFiles(); boolean found = false; for (TFile file : files) if (file.getName().equals(entry)) found = true; if (!found) fail("No such entry: " + entry); }
final String suffix = getSuffix(oldNode.getName()); if (null != suffix) member += suffix;
@Override public String convertValueToText( final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { final TFile node = (TFile) value; final TFile editedNode = getEditedNode(); if (node != editedNode && !node.exists()) { // You will see this occur for files which have been deleted // concurrently or which are returned by TFile.listFiles(), but do // not actually TFile.exists(), such as "C:\hiberfile.sys" on the // Windows platform. return "?"; // NOI18N } final String base = node.getName(); if (base.length() <= 0) return node.getPath(); // This is a file system root. if (node.isDirectory() || isDisplayingSuffixes() && (!node.equals(editedNode) || isEditingSuffixes())) return base; final int i = base.lastIndexOf('.'); return i != -1 ? base.substring(0, i) : base; }
/** * Returns a file object for the same path name, but does not detect any * archive file name patterns in the last path name segment. * The parent file object is unaffected by this transformation, so the * path name of this file object may address an entry in an archive file. * * @return A file object for the same path name, but does not detect any * archive file name patterns in the last path name segment. * @see TVFS#umount(TFile) * @since TrueZIP 7.5 */ @ExpertFeature( level=INTERMEDIATE, value=INJECTING_A_DIFFERENT_DETECTOR_FOR_THE_SAME_PATH_MAY_CORRUPT_DATA) public TFile toNonArchiveFile() { return isArchive() ? new TFile(getParentFile(), getName(), TArchiveDetector.NULL) : this; }
@Override public String getSystemDisplayName(File file) { final TFile tfile = wrap(file); if (tfile.isArchive() || tfile.isEntry()) return tfile.getName(); return delegate.getSystemDisplayName(unwrap(file)); }
try { final TConfig config = TConfig.get(); // Request encryption in archive files. config.setOutputPreferences(config.getOutputPreferences() .or(BitField.of(FsOutputOption.ENCRYPT))); // Configure archive detector with custom key management for ZIP files. config.setArchiveDetector(newArchiveDetector1("zip", "password")); // Setup file paths. TFile src = new TFile("file1"); TFile dst = new TFile("file2"); if (dst.isArchive() || dst.isDirectory()) dst = new TFile(dst, src.getName()); // Recursive copy. src.cp_rp(dst); } finally { // Commit changes. TVFS.umount(); }
@Test public final void testDirectoryTree() throws IOException { assertDirectoryTree( new TFile(System.getProperty("java.io.tmpdir")), // base directory new TFile("dir/inner" + getSuffix() + "/dir/outer" + getSuffix() + "/" + archive.getName())); // this path is reversed!!! }
private void roundTrip(final TFile outer) throws IOException { final TFile inner = new TFile(outer.getParentFile(), "inner" + getSuffix() + "/" + outer.getName()); // This particular sequence has been selected because of its increased // likeliness to fail in case the cache sync logic is not correct. create(inner); check(inner); inner.mv(outer); check(outer); outer.mv(inner); check(inner); inner.rm(); }
private void assertDirectoryTree(TFile basePath, TFile reversePath) throws IOException { if (reversePath == null) { // We're at the leaf of the directory tree. final TFile test = new TFile(basePath, "test.txt"); //testCreateNewFile(basePath, test); assertFileOutputStream(test); return; } final TFile member = new TFile(basePath, reversePath.getName()); final boolean created = member.mkdir(); final TFile children = reversePath.getParentFile(); assertDirectoryTree(member, children); assertListFiles(basePath, member.getName()); assertTrue(member.exists()); assertTrue(member.isDirectory()); assertFalse(member.isFile()); if (member.isArchive()) assertEquals(0, member.length()); if (created) { member.rm(); assertFalse(member.exists()); assertFalse(member.isDirectory()); assertFalse(member.isFile()); assertEquals(0, member.length()); } }