protected OutputStream doGetOutputStream( boolean append ) throws Exception { final File parent = getName().getParent() != null ? searchFile( getName().getParent().getBaseName(), null ) : null; ByteArrayOutputStream out = new ByteArrayOutputStream() { public void close() throws IOException { File file = new File(); file.setName( getName().getBaseName() ); if ( parent != null ) { file.setParents( Collections.singletonList( parent.getId() ) ); } ByteArrayContent fileContent = new ByteArrayContent( "application/octet-stream", toByteArray() ); if ( count > 0 ) { driveService.files().create( file, fileContent ).execute(); ( (GoogleDriveFileSystem) getFileSystem() ).clearFileFromCache( getName() ); } } }; return out; }
private void resolveFileMetadata() throws Exception { String parentId = null; if ( getName().getParent() != null ) { File parent = searchFile( getName().getParent().getBaseName(), null ); if ( parent != null ) { FileType mime = MIME_TYPES.get( parent.getMimeType() ); if ( mime.equals( FileType.FOLDER ) ) { parentId = parent.getId(); } } } String fileName = getName().getBaseName(); File file = searchFile( fileName, parentId ); if ( file != null ) { mimeType = MIME_TYPES.get( file.getMimeType() ); id = file.getId(); } else { if ( getName().getURI().equals( GoogleDriveFileProvider.SCHEME + ":///" ) ) { mimeType = FileType.FOLDER; } } }
FileName fileDir = fileName.getParent(); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() );
/** * Sets the internal filename kettle variables. * * @param var the new internal filename kettle variables */ @Override protected void setInternalFilenameKettleVariables( VariableSpace var ) { if ( filename != null ) { // we have a filename that's defined. try { FileObject fileObject = KettleVFS.getFileObject( filename, var ); FileName fileName = fileObject.getName(); // The filename of the job variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() ); // The directory of the job FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "" ); } setInternalEntryCurrentDirectory(); }
/** * Sets the internal filename kettle variables. * * @param var * the new internal filename kettle variables */ @Override protected void setInternalFilenameKettleVariables( VariableSpace var ) { // If we have a filename that's defined, set variables. If not, clear them. // if ( !Utils.isEmpty( filename ) ) { try { FileObject fileObject = KettleVFS.getFileObject( filename, var ); FileName fileName = fileObject.getName(); // The filename of the transformation variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, fileName.getBaseName() ); // The directory of the transformation FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( KettleFileException e ) { log.logError( "Unexpected error setting internal filename variables!", e ); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, "" ); } setInternalEntryCurrentDirectory(); }
FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) {
FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( KettleFileException e ) {
@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; } }
@Override public FileName getParent() { return fileName.getParent(); }
final FileName base = name.getParent(); return fsManager.resolveName(base, name.getBaseName()).getURI();
private FastStack<String> stackName( FileName fullName ) { final FastStack<String> stack = new FastStack<String>(); while ( fullName != null ) { final String name = fullName.getBaseName().trim(); if ( !name.equals( "" ) ) { stack.push( name ); } fullName = fullName.getParent(); } return stack; }
protected String[] computeFileNames( FileName file ) { final FastStack stack = new FastStack(); while ( file != null ) { final String name = file.getBaseName(); stack.push( name ); file = file.getParent(); } final int size = stack.size(); final String[] result = new String[ size ]; for ( int i = 0; i < result.length; i++ ) { result[ i ] = (String) stack.pop(); } return result; }
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; }
/** * Tests the root file name. */ public void testRootFileName() throws Exception { // Locate the root file final FileName rootName = getReadFolder().getFileSystem().getRoot().getName(); // Test that the root path is "/" assertEquals("root path", "/", rootName.getPath()); // Test that the root basname is "" assertEquals("root base name", "", rootName.getBaseName()); // Test that the root name has no parent assertNull("root parent", rootName.getParent()); }
/** * Tests the root file name. */ public void testRootFileName() throws Exception { // Locate the root file final FileName rootName = getReadFolder().getFileSystem().getRoot().getName(); // Test that the root path is "/" assertEquals("root path", "/", rootName.getPath()); // Test that the root basname is "" assertEquals("root base name", "", rootName.getBaseName()); // Test that the root name has no parent assertNull("root parent", rootName.getParent()); }
/** * Tests the root file name. */ public void testRootFileName() throws Exception { // Locate the root file final FileName rootName = getReadFolder().getFileSystem().getRoot().getName(); // Test that the root path is "/" assertEquals("root path", "/", rootName.getPath()); // Test that the root basname is "" assertEquals("root base name", "", rootName.getBaseName()); // Test that the root name has no parent assertNull("root parent", rootName.getParent()); }