@Override public String getCanonicalPath() { if(!getCanonicalPathSet) { getCanonicalPath = file.getCanonicalPath(); getCanonicalPathSet = true; } return getCanonicalPath; }
@Override public String getCanonicalPath() { return file.getCanonicalPath(); }
/** * Returns <code>true</code> if this file is a parent folder of the given file, or if the two files are equal. * * @param file the AbstractFile to test * @return true if this file is a parent folder of the given file, or if the two files are equal */ public final boolean isParentOf(AbstractFile file) { return isBrowsable() && file.getCanonicalPath(true).startsWith(getCanonicalPath(true)); }
/** * Tests a file for equality by comparing both files' {@link #getCanonicalPath() canonical path}. * Returns <code>true</code> if the canonical path of this file and the specified one are equal. * * <p>It is noteworthy that this method uses <code>java.lang.String#equals(Object)</code> to compare paths, which * in some rare cases may return <code>false</code> for non-ascii/Unicode paths that have the same written * representation but are not equal according to <code>java.lang.String#equals(Object)</code>. Handling such cases * would require a locale-aware String comparison which is not an option here.</p> * * <p>It is also worth noting that hostnames are not resolved, which means this method does not consider * a hostname and its corresponding IP address as being equal.</p> * * <p>Unlike {@link #equals(Object)}, this method <b>is</b> allowed to perform I/O operations and block * the caller thread.</p> * * @param o the object to compare against this instance * @return <code>true</code> if the canonical path of this file and the specified one are equal. * @see #equals(Object) */ public boolean equalsCanonical(Object o) { if(o==null || !(o instanceof AbstractFile)) return false; // TODO: resolve hostnames ? return getCanonicalPath(false).equals(((AbstractFile)o).getCanonicalPath(false)); }
/** * Returns the canonical path to this file, resolving any symbolic links or '..' and '.' occurrences. * A separator character will be appended to the returned path if <code>true</code> is passed. * * @param appendSeparator if true, a separator will be appended to the returned path * @return the canonical path to this file */ public final String getCanonicalPath(boolean appendSeparator) { String path = getCanonicalPath(); return appendSeparator?addTrailingSeparator(path): removeTrailingSeparator(path); }
/** * Adds all <code>/Volumes</code> subfolders to the given <code>Vector</code>. * * @param v the <code>Vector</code> to add the volumes to */ private static void addMacOSXVolumes(Vector<AbstractFile> v) { // /Volumes not resolved for some reason, giving up AbstractFile volumesFolder = FileFactory.getFile("/Volumes"); if(volumesFolder==null) return; // Adds subfolders try { AbstractFile volumesFiles[] = volumesFolder.ls(); int nbFiles = volumesFiles.length; AbstractFile folder; for(int i=0; i<nbFiles; i++) if((folder=volumesFiles[i]).isDirectory()) { // The primary hard drive (the one corresponding to '/') is listed under Volumes and should be // returned as the first volume if(folder.getCanonicalPath().equals("/")) v.insertElementAt(folder, 0); else v.add(folder); } } catch(IOException e) { LOGGER.warn("Can't get /Volumes subfolders", e); } }
/** * Returns <code>true</code> if the given file should have its canonical path followed. In that case, the * AbstractFile instance must be resolved again. * * <p>HTTP files MUST have their canonical path followed. For all other file protocols, this is an option in * the preferences.</p> * * @param file the file to test * @return <code>true</code> if the given file should have its canonical path followed */ private boolean followCanonicalPath(AbstractFile file) { return (MuConfigurations.getPreferences().getVariable(MuPreference.CD_FOLLOWS_SYMLINKS, MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS) || file.getURL().getScheme().equals(FileProtocols.HTTP)) && !file.getAbsolutePath(false).equals(file.getCanonicalPath(false)); }
/** * Returns an <code>AbstractFile</code> representing the canonical path of this file, or <code>this</code> if the * absolute and canonical path of this file are identical.<br/> * Note that the returned file may or may not exist, for example if this file is a symlink to a file that doesn't * exist. * * @return an <code>AbstractFile representing the canonical path of this file, or this if the absolute and canonical * path of this file are identical. */ public AbstractFile getCanonicalFile() { String canonicalPath = getCanonicalPath(false); if(canonicalPath.equals(getAbsolutePath(false))) return this; try { FileURL canonicalURL = FileURL.getFileURL(canonicalPath); canonicalURL.setCredentials(fileURL.getCredentials()); return FileFactory.getFile(canonicalURL); } catch(IOException e) { return this; } }
/** * Tests {@link AbstractFile#getCanonicalPath()} by asserting that it returns a non-null value, that the file can * be resolved again using this path, and that the resolved file is the same as the orginal file. * The tests are performed on a regular file and a directory file. * * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ @Test public void testCanonicalPath() throws IOException, NoSuchAlgorithmException { // Regular file createFile(tempFile, 1); testPathResolution(tempFile.getCanonicalFile(), tempFile.getCanonicalPath()); // Directory file tempFile.delete(); tempFile.mkdir(); testPathResolution(tempFile.getCanonicalFile(), tempFile.getCanonicalPath()); // Test getCanonicalPath(boolean) on the directory file assert tempFile.getCanonicalPath(true).endsWith(tempFile.getSeparator()); assert !tempFile.getCanonicalPath(false).endsWith(tempFile.getSeparator()); }
this.locationField = new JTextField(currentFolder.getCanonicalPath()); compPanel.addRow(Translator.get("location")+":", locationField, 10);
/** * Creates a new FileLabel, showing the file's name or full canonical path depending on the value of * <code>showFullPath</code>. * * @param file the file to show * @param showFullPath if true, the file's canonical path will be displayed, if false its filename. */ public FileLabel(AbstractFile file, boolean showFullPath) { String path = file.getCanonicalPath(); if(showFullPath) { setText(path); } else { setText(file.getName()); setToolTipText(path); } setIcon(FileIcons.getFileIcon(file)); } }
currentPath = currentFolder.getAbsolutePath(false).toLowerCase(); else currentPath = currentFolder.getCanonicalPath(false).toLowerCase(); temp = volumes[i].getAbsolutePath(false).toLowerCase(); else temp = volumes[i].getCanonicalPath(false).toLowerCase();
assert StringUtils.equals(unicodeFile.getName(), children[0].getName(), locale); assert StringUtils.equals(unicodeFile.getAbsolutePath(false), children[0].getAbsolutePath(false), locale); assert StringUtils.equals(unicodeFile.getCanonicalPath(false), children[0].getCanonicalPath(false), locale);
try { FileURL newURL = FileURL.getFileURL(folder.getCanonicalPath());