protected void browseForFileInputPath() { try { String path = space.environmentSubstitute( wPath.getText() ); VfsFileChooserDialog fileChooserDialog; String fileName; if ( path == null || path.length() == 0 ) { fileChooserDialog = getVfsFileChooserDialog( null, null ); fileName = selectedVFSScheme.scheme + "://"; } else { FileObject initialFile = getInitialFile( wPath.getText() ); FileObject rootFile = initialFile.getFileSystem().getRoot(); fileChooserDialog = getVfsFileChooserDialog( rootFile, initialFile ); fileName = null; } FileObject selectedFile = fileChooserDialog.open( getParent().getShell(), null, selectedVFSScheme.scheme, true, fileName, FILES_FILTERS, fileFilterNames, true, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY, true, true ); if ( selectedFile != null ) { String filePath = selectedFile.getURL().toString(); if ( !DEFAULT_LOCAL_PATH.equals( filePath ) ) { wPath.setText( filePath ); updateLocation(); } } } catch ( KettleFileException | FileSystemException ex ) { log.logError( ex.getMessage() ); } }
/** * Removes the listener associated with the provided file from the currently set rootFile. */ public void remove(FileObject fileToRemove, FileListener listener){ filesystem.removeListener(fileToRemove, listener); } }
private FileObject getLinkDestination() throws FileSystemException { if (linkDestination == null) { final String path; synchronized (getFileSystem()) { path = this.fileInfo == null ? null : this.fileInfo.getLink(); } final FileName parent = getName().getParent(); final FileName relativeTo = parent == null ? getName() : parent; final FileName linkDestinationName = getFileSystem().getFileSystemManager().resolveName(relativeTo, path); linkDestination = getFileSystem().resolveFile(linkDestinationName); } return linkDestination; }
/** * Recursively fires create events for all children if recursive descent is enabled. Otherwise the create event * is only fired for the initial FileObject. * * @param child The child to add. */ private void fireAllCreate(final FileObject child) { // Add listener so that it can be triggered if (this.fm.getFileListener() != null) { child.getFileSystem().addListener(child, this.fm.getFileListener()); } ((AbstractFileSystem) child.getFileSystem()).fireFileCreated(child); // Remove it because a listener is added in the queueAddFile if (this.fm.getFileListener() != null) { child.getFileSystem().removeListener(child, this.fm.getFileListener()); } this.fm.queueAddFile(child); // Add try { if (this.fm.isRecursive() && child.getType().hasChildren()) { final FileObject[] newChildren = child.getChildren(); for (final FileObject element : newChildren) { fireAllCreate(element); } } } catch (final FileSystemException fse) { LOG.error(fse.getLocalizedMessage(), fse); } }
/** * returns the wrapped listener. If it is gone, the WeakRefFileListener wrapper will remove itself from the list of * listeners. * * @return The FileListener. * @throws Exception if an error occurs. */ protected FileListener getListener() throws Exception { final FileListener listener = this.listener.get(); if (listener == null) { final FileObject file = fs.resolveFile(name); file.getFileSystem().removeListener(file, this); } return listener; }
/** * Tests the contents of root of file system can be listed. */ public void testRoot() throws FileSystemException { if (!this.getProviderConfig().isFileSystemRootAccessible()) { return; } final FileSystem fs = getFileSystem(); final String uri = fs.getRootURI(); final FileObject file = getManager().resolveFile(uri, fs.getFileSystemOptions()); file.getChildren(); }
/** * Determines if this file can be written to. * * @return {@code true} if this file is writeable, {@code false} if not. * @throws FileSystemException if an error occurs. */ @Override public boolean isWriteable() throws FileSystemException { return getFileSystem().hasCapability(Capability.WRITE_CONTENT); }
private void addCacheEntry( FileName rootName, FileSystem fs ) throws FileSystemException { addFileSystem( getFileSystemKey( rootName.toString(), fs.getFileSystemOptions() ), fs ); String embeddedMetastoreKey = getEmbeddedMetastoreKey( fs.getFileSystemOptions() ); Set<FileSystem> fsSet = cacheEntries.get( embeddedMetastoreKey ); if ( fsSet == null ) { fsSet = Collections.synchronizedSet( new HashSet<FileSystem>() ); cacheEntries.put( embeddedMetastoreKey, fsSet ); } fsSet.add( fs ); }
/** * This will install the {@code listener} at the given {@code file}. * * @param file The FileObject to listen on. * @param listener The FileListener */ public static void installListener(final FileObject file, final FileListener listener) { final WeakRefFileListener weakListener = new WeakRefFileListener(file, listener); file.getFileSystem().addListener(file, new WeakRefFileListener(file, weakListener)); }
/** * Tests setting the last modified time of a folder. * * @throws FileSystemException if error occurred */ public void testSetLastModifiedFolder() throws FileSystemException { final long yesterday = System.currentTimeMillis() - 24 * 60 * 60 * 1000; if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER)) { // Try a folder final FileObject folder = getReadFolder().resolveFile("dir1"); folder.getContent().setLastModifiedTime(yesterday); final long lastModTimeAccuracy = (long) folder.getFileSystem().getLastModTimeAccuracy(); // folder.refresh(); TODO: does not work with SSH VFS-563 final long lastModifiedTime = folder.getContent().getLastModifiedTime(); assertDelta("set/getLastModified on Folder", yesterday, lastModifiedTime, lastModTimeAccuracy); } }
/** * Called while the lock is held * * @param fileSystem The file system to close. */ private void close(final FileSystem fileSystem) { if (log.isDebugEnabled()) { log.debug("close fs: " + fileSystem.getRootName()); } fileSystemCache.remove(fileSystem); if (fileSystemCache.size() < 1) { endThread(); } /* * This is not thread-safe as another thread might be opening the file system ((DefaultFileSystemManager) * getContext().getFileSystemManager()) ._closeFileSystem(filesystem); */ }
private static FileObject resolveFile(final FileSystem fs, final int i) throws FileSystemException { return fs.resolveFile(String.format("%010d", i)); }
/** * Returns the base folder for tests. */ @Override public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { final FileObject baseFolder = config.getBaseTestFolder(manager); // Create an empty file system, then link in the base folder final FileSystem newFs = manager.createVirtualFileSystem("vfs:").getFileSystem(); final String junctionPoint = "/some/dir"; newFs.addJunction(junctionPoint, baseFolder); return newFs.resolveFile(junctionPoint); }
/** * * @param file The file. */ public DefaultFileOperations(final FileObject file) { fileObject = file; fsmanager = file.getFileSystem().getFileSystemManager(); }
private FileObject getLinkDestination() throws FileSystemException { if (linkDestination == null) { final String path; synchronized (getFileSystem()) { path = this.fileInfo.getLink(); } FileName relativeTo = getName().getParent(); if (relativeTo == null) { relativeTo = getName(); } final FileName linkDestinationName = getFileSystem().getFileSystemManager().resolveName(relativeTo, path); linkDestination = getFileSystem().resolveFile(linkDestinationName); } return linkDestination; }
/** * Recursively fires create events for all children if recursive descent is enabled. Otherwise the create event * is only fired for the initial FileObject. * * @param child The child to add. */ private void fireAllCreate(final FileObject child) { // Add listener so that it can be triggered if (this.fm.getFileListener() != null) { child.getFileSystem().addListener(child, this.fm.getFileListener()); } ((AbstractFileSystem) child.getFileSystem()).fireFileCreated(child); // Remove it because a listener is added in the queueAddFile if (this.fm.getFileListener() != null) { child.getFileSystem().removeListener(child, this.fm.getFileListener()); } this.fm.queueAddFile(child); // Add try { if (this.fm.isRecursive() && child.getType().hasChildren()) { final FileObject[] newChildren = child.getChildren(); for (final FileObject element : newChildren) { fireAllCreate(element); } } } catch (final FileSystemException fse) { LOG.error(fse.getLocalizedMessage(), fse); } }
/** * returns the wrapped listener. If it is gone, the WeakRefFileListener wrapper will * remove itself from the list of listeners. * @return The FileListener. * @throws Exception if an error occurs. */ protected FileListener getListener() throws Exception { final FileListener listener = this.listener.get(); if (listener == null) { final FileObject file = fs.resolveFile(name); file.getFileSystem().removeListener(file, this); } return listener; }
/** * Tests root of file system exists. */ public void testRootURI() throws FileSystemException { if (!this.getProviderConfig().isFileSystemRootAccessible()) { return; } final FileSystem fileSystem = getFileSystem(); final String uri = fileSystem.getRootURI(); testRoot(getManager().resolveFile(uri, fileSystem.getFileSystemOptions())); }
/** * Determines if this file can be written to. * * @return {@code true} if this file is writeable, {@code false} if not. * @throws FileSystemException if an error occurs. */ @Override public boolean isWriteable() throws FileSystemException { return getFileSystem().hasCapability(Capability.WRITE_CONTENT); }
/** * Resolves a URI, relative to a base file. * * @param baseFile The base FileOjbect to use to locate the file. * @param uri The URI of the file to locate. * @return The FileObject for the located file. * @throws FileSystemException if the file cannot be located or an error occurs. */ @Override public FileObject resolveFile(final FileObject baseFile, final String uri) throws FileSystemException { return resolveFile(baseFile, uri, baseFile == null ? null : baseFile.getFileSystem().getFileSystemOptions()); }