@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; }
/** * Background information: <code>jcifs.smb.SmbFile</code> is a tad cumbersome to work with because it requires its * file path to end with '/' when the file is a directory and vice-versa. * This method ensures that the path of the current <code>jcifs.smb.SmbFile</code> instance matches the * <code>directory</code> argument and if not, recreates it with the proper path. * * @param directory true if the current <code>jcifs.smb.SmbFile</code> designates a directory */ private void checkSmbFile(boolean directory) { try { String path = file.getURL().getPath(); boolean endsWithSeparator = path.endsWith("/"); if(directory) { if(!endsWithSeparator) { fileURL.setPath(path+"/"); file = createSmbFile(fileURL); } } else { if(endsWithSeparator) { fileURL.setPath(removeTrailingSeparator(path)); file = createSmbFile(fileURL); } } } catch(MalformedURLException e) { // This should never happen. If some reason wicked reason it ever did, SmbFile would just not be changed. } }
private void fixPathInVmIfNeeded(VsphereConnHandler connHandler) throws RuntimeFaultFaultMsg, RemoteException, InvalidPropertyFaultMsg { if (this.guestOsId == null) { if (connHandler != null) { this.guestOsId = (String) connHandler.getClient() .getProperties(vm, "config.guestId")[0]; } } boolean isWin = false; if (this.guestOsId != null) { // is it a windows machine ? // see possible values for guest id here: // http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html isWin = guestOsId.startsWith("win"); } if (pathInsideVm.isEmpty()) { if (isWin) { // we assume that "C:" is a good default for windows pathInsideVm = "C:"; } else { pathInsideVm = "/"; } // set the url to reflect the path inside the vm fileURL.setPath(fileURL.getPath() + pathInsideVm); } }
@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; }
/** * 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[] 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; }
@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; }
@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; } });
/** * 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; } }
/** * 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); } }
FileURL archiveURL = getURL(); FileURL entryURL = (FileURL)archiveURL.clone(); entryURL.setPath(addTrailingSeparator(archiveURL.getPath()) + entryPath);
/** * Handles the parsing of the given local file URL. * * @param url the URL to parse * @param fileURL the FileURL instance in which to set the different parsed parts */ private void handleLocalFilePath(String url, FileURL fileURL) { SchemeHandler handler = FileURL.getRegisteredHandler(FileProtocols.FILE); SchemeParser parser = handler.getParser(); fileURL.setHandler(handler); fileURL.setScheme(FileProtocols.FILE); fileURL.setHost(FileURL.LOCALHOST); fileURL.setPath((parser instanceof DefaultSchemeParser?((DefaultSchemeParser)parser).getPathCanonizer():pathCanonizer).canonize(url)); }
canonicalURL.setPath(symlinkTargetPath);
childURL.setPath(smbFile.getURL().getPath());
/** * 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(); } }
tempFileURLB.setPath(tempFile.addTrailingSeparator(tempFileURLB.getPath())); AbstractFile tempFileB = FileFactory.getFile(tempFileURLB, true);