@Override public URL getURL() throws FileSystemException { try { return new URL( fullyQualifiedName ); } catch ( MalformedURLException e ) { throw new FileSystemException( e ); } }
destinationfilefolder = KettleVFS.getFileObject( realDestinationFilefoldername, this ); if ( sourcefilefolder.exists() ) { if ( sourcefilefolder.getType().equals( FileType.FOLDER ) && destination_is_a_file ) { if ( destinationfilefolder.getType().equals( FileType.FOLDER ) && sourcefilefolder.getType().equals( FileType.FILE ) ) { destinationfilefolder.copyFrom( sourcefilefolder.getParent(), new TextOneFileSelector( sourcefilefolder.getParent().toString(), sourcefilefolder.getName().getBaseName(), destinationfilefolder.toString() ) ); if ( isDetailed() ) { .getMessage() ) ); Throwable throwable = fse.getCause(); while ( throwable != null ) { logError( BaseMessages.getString( PKG, "JobCopyFiles.Log.CausedBy", throwable.getMessage() ) );
public void widgetSelected( SelectionEvent e ) { try { FileObject fileName = null; try { String curFile = wFilename.getText(); if ( curFile.trim().length() > 0 ) { fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile( jobMeta.environmentSubstitute( wFilename.getText() ) ); } else { fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile( Const.getUserHomeDirectory() ); } } catch ( FileSystemException ex ) { fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile( Const.getUserHomeDirectory() ); } VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog( fileName.getParent(), fileName ); FileObject selected = vfsFileChooser.open( shell, null, EXTENSIONS, FILETYPES, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE ); wFilename.setText( selected != null ? selected.getURL().toString() : Const.EMPTY_STRING ); } catch ( FileSystemException ex ) { ex.printStackTrace(); } } } );
@Override public void setParameter( FileSystemOptions opts, String name, String value, String fullParameterName, String vfsUrl ) throws IOException { // Use the DelgatingFileSystemOptionsBuilder to insert generic parameters // This must be done to assure the correct VFS FileSystem drivers will process the parameters String scheme = extractScheme( fullParameterName ); try { DelegatingFileSystemOptionsBuilder delegateFSOptionsBuilder = new DelegatingFileSystemOptionsBuilder( KettleVFS.getInstance().getFileSystemManager() ); if ( scheme != null ) { delegateFSOptionsBuilder.setConfigString( opts, scheme, name, value ); } else { log.logMinimal( "Warning: Cannot process VFS parameters if no scheme is specified: " + vfsUrl ); } } catch ( FileSystemException e ) { if ( ( e.getCode() != null ) && ( e.getCode().equalsIgnoreCase( "vfs.provider/config-key-invalid.error" ) ) ) { // This key is not supported by the default scheme config builder. This may be a custom key of another config // builder log.logMinimal( "Warning: The configuration parameter [" + name + "] is not supported by the default configuration builder for scheme: " + scheme ); } else { // An unexpected error has occurred loading in parameters throw new IOException( e.getLocalizedMessage(), e ); } } } }
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "input files are specified by admin, not unchecked user input") @Override public File replicateFile(FileObject srcFile, FileSelector selector) throws FileSystemException { String baseName = srcFile.getName().getBaseName(); try { String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); File file = File.createTempFile("vfsr_", "_" + safeBasename, tempDir); file.deleteOnExit(); final FileObject destFile = context.toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } catch (IOException e) { throw new FileSystemException(e); } }
if ( !fileObject.exists() ) { throw new KettleException( BaseMessages.getString( PKG, "GPLoad.Execption.FileDoesNotExist", pathToFile ) ); FileObject parentFolder = fileObject.getParent(); if ( parentFolder.exists() ) { return KettleVFS.getFilename( fileObject ); } else { throw new KettleException( BaseMessages.getString( PKG, "GPLoad.Exception.GPLoadCommandBuild", fsex.getMessage() ) );
public static void closeQuietly(FileObject fileObject) { if (fileObject != null) { String friendlyURI = fileObject.getName().getFriendlyURI(); try { LOGGER.info(String.format("Closing file %s", friendlyURI)); fileObject.close(); LOGGER.info(String.format("File %s closed", friendlyURI)); } catch (FileSystemException ignore) { LOGGER.error(String.format("File %s is not closed: %s", friendlyURI, ignore.getMessage())); } } }
if (url != null) final FileName name = fsManager.resolveURI(url.toString()); if (name != null) final FileName base = fsManager.resolveURI(basePath); return fsManager.resolveName(base, fileName).getURI(); final FileName name = fsManager.resolveURI(fileName); final FileName base = name.getParent(); return fsManager.resolveName(base, name.getBaseName()).getURI(); fse.printStackTrace(); return null;
/** * Called when the children of this file change. */ @Override protected void onChildrenChanged(final FileName child, final FileType newType) { if (children != null && newType.equals(FileType.IMAGINARY)) { try { children.remove(UriParser.decode(child.getBaseName())); } catch (final FileSystemException e) { throw new RuntimeException(e.getMessage()); } } else { // if child was added we have to rescan the children // TODO - get rid of this children = null; } }
public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { if ( ( data.dis != null ) && ( data.dis.size() > 0 ) ) { for ( DataInputStream is : data.dis ) { BaseStep.closeQuietly( is ); } } // remove temp files for ( int f = 0; f < data.files.size(); f++ ) { FileObject fileToDelete = data.files.get( f ); try { if ( fileToDelete != null && fileToDelete.exists() ) { fileToDelete.delete(); } } catch ( FileSystemException e ) { logError( e.getLocalizedMessage(), e ); } } super.dispose( smi, sdi ); }
if(LOG.isDebugEnabled()) { for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) { LOG.error("{} - {}", fo.getURL(), fo.exists()); LOG.error("Unable to process filesystem: {}", e.getMessage(), e);
protected void doRename(FileObject newfile) throws Exception { final SftpClient sftp = fs.getClient(); try { String oldName = getName().getPathDecoded(); String newName = newfile.getName().getPathDecoded(); if (oldName.equals(newName)) { throw new FileSystemException( "vfs.provider.sftp/rename-identical-files", new Object[] { newName }); } sftp.rename(oldName, newName); } finally { fs.putClient(sftp); } }
@Override protected InputStream doGetInputStream() throws Exception { // VFS-210: ram allows to gather an input stream even from a directory. So we need to check the type anyway. if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); } return new ByteArrayInputStream(this.data.getContent()); }
private URI getURI() { try { // Doing some URL encoding here (e.g. replacing sharp, spaces) // TODO want a general way to handle the URL encoding; may need improvements from commons VFS ... return new URI(this.getName().getURI() .replace("#", "%23") .replace(" ", "%20") .replace("{", "%7B") .replace("}", "%7D") ); } catch (URISyntaxException e) { throw new VFSFileSystemException(new FileSystemException(e)); } }
/** * Tests a {@link FileSystemException} containing info with a nested URL containing a complete basic authentication. */ @Test public void testProperDetectionOfUrl() { final FileSystemException fse = new FileSystemException("vfs.provider/delete.error", "zip:http://foo:bar@junit.org/test.bin"); assertEquals("zip:http://foo:***@junit.org/test.bin", fse.getInfo()[0]); }
@Override public String getFileName(final String path) { if (UriParser.extractScheme(path) == null) { return super.getFileName(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getBaseName(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
@Override public String getBasePath(final String path) { if (UriParser.extractScheme(path) == null) { return super.getBasePath(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getParent().getURI(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
private synchronized FileObject processFile( FileName name, boolean useCache ) throws FileSystemException { if ( !super.getRootName().getRootURI().equals( name.getRootURI() ) ) { throw new FileSystemException( "vfs.provider/mismatched-fs-for-name.error", new Object[] { name, super.getRootName(), name.getRootURI() } ); } else { FileObject file; if ( useCache ) { file = super.getFileFromCache( name ); } else { file = null; } if ( file == null ) { try { file = this.createFile( (AbstractFileName) name ); } catch ( Exception var5 ) { return null; } file = super.decorateFileObject( file ); if ( useCache ) { super.putFileToCache( file ); } } if ( super.getFileSystemManager().getCacheStrategy().equals( CacheStrategy.ON_RESOLVE ) ) { file.refresh(); } return file; } }
public static void main(String[] args) { FileSystemManager fsManager = null; String path = "\\\\myip\\storage\\ogg\\VX-276.ogg"; try { fsManager = VFS.getManager(); FileObject basePath; basePath = fsManager.resolveFile("file:" + path); if (basePath.exists()) System.out.println("exists"); else { System.out.println("missing" + basePath.getURL()); } } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
protected void injectType(final FileType fileType) { if (fileType != null && fileType != FileType.IMAGINARY) { try { fileName.setType(fileType); } catch (final FileSystemException e) { throw new RuntimeException(e.getMessage()); } } this.type = fileType; }