@Override public URL getURL() throws FileSystemException { try { return new URL( fullyQualifiedName ); } catch ( MalformedURLException e ) { throw new FileSystemException( e ); } }
public FileObject resolveFile( String fileUri ) throws FileSystemException { try { return KettleVFS.getFileObject( fileUri, getVariableSpace(), getFileSystemOptions() ); } catch ( KettleFileException e ) { throw new FileSystemException( e ); } }
protected GoogleDriveFileObject( final AbstractFileName fileName, final GoogleDriveFileSystem fileSystem ) throws FileSystemException { super( fileName, fileSystem ); try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new CustomDataStoreFactory( DATA_STORE_DIR ); driveService = getDriveService(); resolveFileMetadata(); } catch ( Exception e ) { throw new FileSystemException( e ); } }
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; } }
/** * {@link org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() } * */ private void ensureSession() throws FileSystemException { if ( this.session == null || !this.session.isConnected() ) { this.doCloseCommunicationLink(); UserAuthenticationData authData = null; Session session; try { GenericFileName e = (GenericFileName) this.getRootName(); authData = UserAuthenticatorUtils.authenticate( this.getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES ); session = SftpClientFactory.createConnection( e.getHostName(), e.getPort(), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar( e.getUserName() ) ), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar( e.getPassword() ) ), this.getFileSystemOptions() ); } catch ( Exception var7 ) { throw new FileSystemException( "vfs.provider.sftp/connect.error", this.getRootName(), var7 ); } finally { UserAuthenticatorUtils.cleanup( authData ); } this.session = session; } }
@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); } }
/** * Removes a junction from this file system. * * @param junctionPoint The junction point. * @throws FileSystemException if an error occurs */ @Override public void removeJunction(final String junctionPoint) throws FileSystemException { throw new FileSystemException("vfs.provider/junctions-not-supported.error", rootName); }
/** * @see org.apache.commons.vfs2.provider.AbstractFileSystem#createFile(AbstractFileName) */ @Override protected FileObject createFile(final AbstractFileName name) throws Exception { throw new FileSystemException("Operation not supported"); }
/** * Removes a junction from this file system. * * @param junctionPoint The junction point. * @throws FileSystemException if an error occurs */ @Override public void removeJunction(final String junctionPoint) throws FileSystemException { throw new FileSystemException("vfs.provider/junctions-not-supported.error", rootName); }
/** * Sets the type of this file e.g. when it will be attached. * * @param type {@link FileType#FOLDER} or {@link FileType#FILE} * @throws FileSystemException if an error occurs. */ void setType(final FileType type) throws FileSystemException { if (type != FileType.FOLDER && type != FileType.FILE && type != FileType.FILE_OR_FOLDER) { throw new FileSystemException("vfs.provider/filename-type.error"); } this.type = type; }
@Override protected ZipFile createZipFile(final File file) throws FileSystemException { try { return new JarFile(file); } catch (final IOException ioe) { throw new FileSystemException("vfs.provider.jar/open-jar-file.error", file, ioe); } }
/** * Closes this input stream. */ @Override public void close() throws FileSystemException { try { super.close(); } catch (final IOException e) { throw new FileSystemException("vfs.provider/close-instr.error", file, e); } }
/** * Creates a provider. */ private Object createInstance(final String className) throws FileSystemException { try { final Class<?> clazz = loadClass(className); return clazz.newInstance(); } catch (final Exception e) { throw new FileSystemException("vfs.impl/create-provider.error", className, e); } }
/** * Closes this input stream. */ @Override public void close() throws FileSystemException { try { super.close(); } catch (final IOException e) { throw new FileSystemException("vfs.provider/close-instr.error", file, e); } }
Object getAttribute(final Name attrName) throws FileSystemException { try { final Attributes attr = getAttributes(); final String value = attr.getValue(attrName); return value; } catch (final IOException ioe) { throw new FileSystemException(attrName.toString(), ioe); } }
@Override public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException { try { return exists() ? doSetReadable(readable, ownerOnly) : false; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/set-readable.error", fileName, exc); } }
@Override protected long doGetLastModifiedTime() throws Exception { if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) == 0) { throw new FileSystemException("vfs.provider.sftp/unknown-modtime.error"); } return attrs.getMTime() * MOD_TIME_FACTOR; }
@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()); }
@Override protected void doDelete() throws Exception { if (this.isContentOpen()) { throw new FileSystemException(this.getName() + " cannot be deleted while the file is openg"); } getAbstractFileSystem().delete(this); }
/** * 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]); }