private String getObjectKey() { String urlPath = fileURL.getPath(); // Strip out the bucket name from the path return urlPath.substring(bucketName.length()+2, urlPath.length()); }
protected SFTPFile(FileURL fileURL, SFTPFileAttributes fileAttributes) throws IOException { super(fileURL); // // Throw an AuthException if the url doesn't contain any credentials // if(!fileURL.containsCredentials()) // throw new AuthException(fileURL); this.absPath = fileURL.getPath(); if(fileAttributes==null) this.fileAttributes = new SFTPFileAttributes(fileURL); else this.fileAttributes = fileAttributes; }
/** * Returns <code>true</code> if this file is a root folder. * <p> * This default implementation returns <code>true</code> if this file's URL path is <code>/</code>. * </p> * * @return <code>true</code> if this file is a root folder */ public boolean isRoot() { return getURL().getPath().equals("/"); }
@Override public String toString() { if (!FileProtocols.FILE.equals(url.getScheme())) return url.toString(); String path = url.getPath(); if (LocalFile.USES_ROOT_DRIVES && !path.isEmpty()) path = path.substring(1); return path; }
/** * Creates a new OpenLocationAction instance using the provided url's string representation * (with credentials stripped out) as label. */ public OpenLocationAction(MainFrame mainFrame, Map<String,Object> properties, FileURL url) { this(mainFrame, properties, url, url.getScheme().equals(FileProtocols.FILE)?url.getPath():url.toString(false)); }
/** * Asserts that the path of the given URL is equal to the given expected path. * * @param expectedPath the expected path * @param url URL to test */ protected void assertPathEquals(String expectedPath, FileURL url) { assert expectedPath.equals(url.getPath()); }
/** * Creates a new instance of UNCFile, using the given {@link File} if not <code>null</code>, creating a new * {@link File} instance otherwise. */ protected UNCFile(FileURL fileURL, File file) throws IOException { super(fileURL); if(file==null) { absPath = SEPARATOR+SEPARATOR+fileURL.getHost()+fileURL.getPath().replace('/', '\\'); // Replace leading / char by \ // Create the java.io.File instance and throw an exception if the path is not absolute. file = new File(absPath); if(!file.isAbsolute()) throw new IOException(); } // the java.io.File instance was created by ls(), no need to re-create it or call the costly File#getAbsolutePath() else { absPath = SEPARATOR+SEPARATOR+fileURL.getHost()+fileURL.getPath().replace('/', '\\'); } // Remove the trailing separator if present if(absPath.endsWith(SEPARATOR)) absPath = absPath.substring(0, absPath.length()-1); this.file = file; this.permissions = new UNCFilePermissions(file); }
/** * Creates a new OpenLocationAction instance using the provided FileURL and label. */ public OpenLocationAction(MainFrame mainFrame, Map<String,Object> properties, FileURL url, String label) { super(mainFrame, properties); this.url = url; setLabel(label); setToolTipText(url.getScheme().equals(FileProtocols.FILE)?url.getPath():url.toString(false)); }
public VSphereFile(FileURL url, VSphereFile parent, GuestFileInfo guestFileInfo) throws RuntimeFaultFaultMsg, IOException, FileFaultFaultMsg, GuestOperationsFaultFaultMsg, InvalidStateFaultMsg, TaskInProgressFaultMsg, InvalidPropertyFaultMsg, URISyntaxException { super(url); setPath(url.getPath()); this.parent = parent; this.vm = parent.vm; this.guestOsId = parent.guestOsId; this.guestOperationsManager = parent.guestOperationsManager; fixPathInVmIfNeeded(null); updateAttributes(guestFileInfo); }
@Override public AbstractFile[] ls(FilenameFilter filenameFilter) throws IOException { File files[] = file.listFiles(filenameFilter==null?null:new UNCFilenameFilter(filenameFilter)); if(files==null) throw new IOException(); int nbFiles = files.length; AbstractFile children[] = new AbstractFile[nbFiles]; FileURL childURL; File file; for(int i=0; i<nbFiles; i++) { file = files[i]; // Clone the FileURL of this file and set the child's path, this is more efficient than creating a new // FileURL instance from scratch. childURL = (FileURL)fileURL.clone(); childURL.setPath(addTrailingSeparator(fileURL.getPath())+file.getName()); // Retrieves an AbstractFile (LocalFile or AbstractArchiveFile) instance that's potentially already in // the cache, reuse this file as the file's parent, and the already-created java.io.File instance. children[i] = FileFactory.getFile(childURL, this, file); } return children; }
protected HTTPFile(FileURL fileURL, URL url) throws IOException { super(fileURL); String scheme = fileURL.getScheme().toLowerCase(); if((!scheme.equals(FileProtocols.HTTP) && !scheme.equals(FileProtocols.HTTPS)) || fileURL.getHost()==null) throw new IOException(); this.url = url; attributes = getDefaultAttributes(); String mimeType; String filename = fileURL.getFilename(); // Simple/fuzzy heuristic to avoid file resolution (HEAD) in cases where we have good reasons to believe that // the URL denotes a HTML/XTHML document: // - URL's path has no filename (e.g. http://www.mucommander.com/) or path ends with '/' (e.g. http://www.mucommander.com/download/) // - URL has a query part (works most of the time, must not always) // - URL has an extension that registered with an HTML/XHTML mime type if((filename==null || fileURL.getPath().endsWith("/") || fileURL.getQuery()!=null || ((mimeType=MimeTypes.getMimeType(this))!=null && isParsableMimeType(mimeType)))) { attributes.setDirectory(true); resolve = false; } else { resolve = true; } }
@Override public AbstractFile[] ls(FilenameFilter filenameFilter) throws IOException { String names[] = file.list(); if(names==null) throw new IOException(); if(filenameFilter!=null) names = filenameFilter.filter(names); AbstractFile children[] = new AbstractFile[names.length]; FileURL childURL; String baseURLPath = fileURL.getPath(); if(!baseURLPath.endsWith("/")) baseURLPath += SEPARATOR; for(int i=0; i<names.length; i++) { // Clone this file's URL with the connection properties and set the child file's path childURL = (FileURL)fileURL.clone(); childURL.setPath(baseURLPath+names[i]); // Create the child NFSFile using this file as a parent children[i] = FileFactory.getFile(childURL, this); } return children; }
/** * Adds a dummy output file (used in progress monitoring). * @param i index of a file * @param size size of a file */ private void addDummyFile(int i, long size) { String num; if (i<10) { num = "00" + Integer.toString(i); } else if (i<100) { num = "0" + Integer.toString(i); } else { num = Integer.toString(i); } FileURL childURL = (FileURL)destFolder.getURL().clone(); childURL.setPath(destFolder.addTrailingSeparator(childURL.getPath()) + sourceFile.getName() + "." + num); DummyDestFile fileHolder = new DummyDestFile(childURL, size); files.add(fileHolder); }
@Override public AbstractFile getCanonicalFile() { if(!isSymlink()) return this; // Create the canonical file instance and cache it if(canonicalFile==null) { // getLink() returns the raw symlink target which can either be an absolute or a relative path. If the path is // relative, preprend the absolute path of the symlink's parent folder. String symlinkTargetPath = file.getLink(); if(!symlinkTargetPath.startsWith("/")) { String parentPath = fileURL.getParent().getPath(); if(!parentPath.endsWith("/")) parentPath += "/"; symlinkTargetPath = parentPath + symlinkTargetPath; } FileURL canonicalURL = (FileURL)fileURL.clone(); canonicalURL.setPath(symlinkTargetPath); canonicalFile = FileFactory.getFile(canonicalURL); } return canonicalFile; }
@Override public FileURL getRealm(FileURL location) { FileURL realm = new FileURL(this); String newPath = location.getPath(); // Find first path token (share) int pos = newPath.indexOf('/', 1); newPath = newPath.substring(0, pos==-1?newPath.length():pos+1); realm.setPath(newPath); realm.setScheme(location.getScheme()); realm.setHost(location.getHost()); realm.setPort(location.getPort()); // Copy properties (if any) realm.importProperties(location); return realm; } });
/** * Tests the resolution of Windows UNC paths (e.g. \\host\\share). This test is system-dependant. * * @throws MalformedURLException should not happen */ @Test public void testUNCParsing() throws MalformedURLException { FileURL url = FileURL.getFileURL("\\\\host\\share"); // UNC path will be transformed into either a 'file' or a 'smb' URL, depending on the current OS assert (OsFamily.WINDOWS.isCurrent()?"file":"smb").equals(url.getScheme()); assert "host".equals(url.getHost()); assert "/share".equals(url.getPath()); }
protected FTPFile(FileURL fileURL, org.apache.commons.net.ftp.FTPFile file) throws IOException { super(fileURL); this.absPath = fileURL.getPath(); if(file==null) { this.file = getFTPFile(fileURL); // If file doesn't exist (could not be resolved), create it if(this.file==null) { String name = fileURL.getFilename(); // Filename could potentially be null this.file = createFTPFile(name==null?"":name, false); this.fileExists = false; } else { this.fileExists = true; } } else { this.file = file; this.fileExists = true; } this.permissions = new FTPFilePermissions(this.file); }
/** * Returns a child of this file, whose path is the concatenation of this file's path and the given relative path. * Although this method does not enforce it, the specified path should be relative, i.e. should not start with * a separator.<br/> * An <code>IOException</code> may be thrown if the child file could not be instantiated but the returned file * instance should never be <code>null</code>. * * @param relativePath the child's path, relative to this file's path * @return an AbstractFile representing the requested child file, never null * @throws IOException if the child file could not be instantiated */ public final AbstractFile getChild(String relativePath) throws IOException { FileURL childURL = (FileURL)getURL().clone(); childURL.setPath(addTrailingSeparator(childURL.getPath())+ relativePath); return FileFactory.getFile(childURL, true); }
public VSphereFile(FileURL url, VSphereFile related) throws URISyntaxException, IOException, RuntimeFaultFaultMsg, InvalidPropertyFaultMsg, FileFaultFaultMsg, GuestOperationsFaultFaultMsg, InvalidStateFaultMsg, TaskInProgressFaultMsg { super(url); setPath(url.getPath()); this.vm = related.vm; this.guestOsId = related.guestOsId; this.guestOperationsManager = related.guestOperationsManager; fixPathInVmIfNeeded(null); VsphereConnHandler connHandler = null; try { connHandler = getConnHandler(); checkAttributues(connHandler); } finally { releaseConnHandler(connHandler); } }
@Override public void update(FileTableTab tab, int index) { if (JavaVersion.JAVA_1_5.isCurrentOrLower()) { /*setLockedAt(index, tab.isLocked()); setTitleAt(index, tab.getLocation().getName()); */ } else { setTabHeader(index, headersFactory.create(tab)); } String locationText = tab.getLocation().getPath(); // For OSes with 'root drives' (Windows, OS/2), remove the leading '/' character if(LocalFile.hasRootDrives()) locationText = PathUtils.removeLeadingSeparator(locationText, "/"); setToolTipTextAt(index, locationText); SwingUtilities.invokeLater(() -> validate()); }