/** * Throws an {@link AuthException} using this connection handler's realm, credentials and the message passed as * an argument (can be <code>null</code>). The FileURL instance representing the realm that is used to create * the <code>AuthException</code> is a clone of this realm, making it safe for modification. * * @param message the message to pass to AuthException's constructor, can be <code>null</code> * @throws AuthException always throws the created AuthException */ public void throwAuthException(String message) throws AuthException { FileURL clonedRealm = (FileURL)realm.clone(); clonedRealm.setCredentials(credentials); throw new AuthException(clonedRealm, message); }
@Override public AbstractFile[] ls(FilenameFilter filenameFilter) throws IOException { File files[] = file.listFiles(filenameFilter==null?null:new LocalFilenameFilter(filenameFilter)); if(files==null) throw new IOException(); int nbFiles = files.length; AbstractFile children[] = new AbstractFile[nbFiles]; FileURL childURL; for(int i=0; i<nbFiles; 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(absPath+SEPARATOR+files[i].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, files[i]); } return children; }
@Override public AbstractFile[] ls(FilenameFilter filter) throws IOException { // We need to ensure that the file is a directory: if it isn't listStatus returns an empty array but doesn't // throw an exception if(!exists() || !isDirectory()) throw new IOException(); FileStatus[] statuses = filter==null ?fs.listStatus(path) :fs.listStatus(path, new HadoopFilenameFilter(filter)); int nbChildren = statuses==null?0:statuses.length; AbstractFile[] children = new AbstractFile[nbChildren]; String parentPath = fileURL.getPath(); if(!parentPath.endsWith("/")) parentPath += "/"; FileURL childURL; FileStatus childStatus; for(int i=0; i<nbChildren; i++) { childStatus = statuses[i]; childURL = (FileURL)fileURL.clone(); childURL.setPath(parentPath + childStatus.getPath().getName()); children[i] = FileFactory.getFile(childURL, this, fs, childStatus); } return children; }
@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; }
/** * Returns the root folder of this file, i.e. the top-level parent folder that has no parent folder. The returned * folder necessarily contains this file, directly or indirectly. If this file already is a root folder, the same * file will be returned. * <p> * This default implementation returns the file whose URL has the same scheme as this one, same credentials (if any), * and a path equal to <code>/</code>. * </p> * * @return the root folder that contains this file */ public AbstractFile getRoot() { FileURL rootURL = (FileURL)getURL().clone(); rootURL.setPath("/"); return FileFactory.getFile(rootURL); }
@Override public AbstractFile getRoot() { FileURL rootURL = (FileURL) getURL().clone(); String rootPath = getRootPath(); rootURL.setPath("/" + vmIdentifier + "/" + rootPath); return FileFactory.getFile(rootURL); }
@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; }
childURL = (FileURL)fileURL.clone(); childURL.setPath(parentPath+childName);
/** * Returns a URL with the same scheme, host and port (if any) as the specified URL, and a path set to * <code>"/"</code> or <code>"\"</code> depending on the URL format. * The login, password, query and fragment parts of the returned URL are always <code>null</code>. * For example, when called with <code>http://www.mucommander.com:8080/path/to/file?query¶m=value</code>, * this method returns <code>http://www.mucommander.com:8080/</code>. * * @param location the location for which to return the authentication realm * @return the authentication realm of the specified location */ public FileURL getRealm(FileURL location) { // Start by cloning the given URL and then modify the parts that need it FileURL realm = (FileURL)location.clone(); realm.setPath(location.getPathSeparator()); realm.setCredentials(null); realm.setQuery(null); // Todo // realm.setFragment(null) return realm; } }
public Object getElementAt(int i) { ConnectionHandler connHandler = connections.get(i); // Show login (but not password) in the URL // Note: realm returned by ConnectionHandler does not contain credentials FileURL clonedRealm = (FileURL)connHandler.getRealm().clone(); Credentials loginCredentials = new Credentials(connHandler.getCredentials().getLogin(), ""); clonedRealm.setCredentials(loginCredentials); return clonedRealm.toString(true) +" ("+Translator.get(connHandler.isLocked()?"server_connections_dialog.connection_busy":"server_connections_dialog.connection_idle")+")"; } });
/** * 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); }
@Override public AbstractFile[] ls() throws IOException { try { org.jets3t.service.model.S3Bucket buckets[] = service.listAllBuckets(); int nbBuckets = buckets.length; AbstractFile bucketFiles[] = new AbstractFile[nbBuckets]; FileURL bucketURL; for(int i=0; i<nbBuckets; i++) { bucketURL = (FileURL)fileURL.clone(); bucketURL.setPath("/"+buckets[i].getName()); bucketFiles[i] = FileFactory.getFile(bucketURL, null, service, buckets[i]); } return bucketFiles; } catch(S3ServiceException e) { throw getIOException(e); } }
if(entryFile==null) { FileURL archiveURL = getURL(); FileURL entryURL = (FileURL)archiveURL.clone(); entryURL.setPath(addTrailingSeparator(archiveURL.getPath()) + entryPath);
FileURL canonicalURL = (FileURL)fileURL.clone(); canonicalURL.setPath(symlinkTargetPath);
/** * Tests {@link FileURL#clone()}. * * @throws MalformedURLException should not happen */ @Test public void testClone() throws MalformedURLException { FileURL url = getURL("login", "password", "host", 10000, "/path/to", "query"); url.setProperty("name", "value"); FileURL clonedURL = (FileURL)url.clone(); // Assert that both instances are equal according to FileURL#equals assertEquals(url, clonedURL); // Assert that both URL's string representations (with credentials) are equal assert url.toString(true).equals(clonedURL.toString(true)); // Assert that both instances are not one and the same assert url!=clonedURL; // Assert that the property has survived the cloning assert "value".equals(clonedURL.getProperty("name")); }
/** * Opens a stream on the right file. * <p> * If a backup file is found, and is bigger than the target file, then it will be used. * </p> * @param file file on which to open an input stream. * @return a stream on the right file. * @exception IOException thrown if any IO related error occurs. */ private static InputStream getInputStream(AbstractFile file) throws IOException { AbstractFile backup; FileURL test; test = (FileURL)file.getURL().clone(); test.setPath(test.getPath() + BACKUP_SUFFIX); // Checks whether the backup file is a better choice than the target one. backup = FileFactory.getFile(test); if(backup != null && backup.exists() && (file.getSize() < backup.getSize())) return backup.getInputStream(); // Opens a stream on the target file. return file.getInputStream(); } }
public void testIsDirectory() throws IOException { FileURL tempFileURLB = (FileURL)tempFile.getURL().clone(); tempFileURLB.setPath(tempFile.addTrailingSeparator(tempFileURLB.getPath())); AbstractFile tempFileB = FileFactory.getFile(tempFileURLB, true);