Java Code Examples for org.apache.commons.vfs2.FileType#FOLDER
The following examples show how to use
org.apache.commons.vfs2.FileType#FOLDER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Shell.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Lists the children of a folder. */ private void listChildren(final FileObject dir, final boolean recursive, final String prefix) throws FileSystemException { final FileObject[] children = dir.getChildren(); for (final FileObject child : children) { System.out.print(prefix); System.out.print(child.getName().getBaseName()); if (child.getType() == FileType.FOLDER) { System.out.println("/"); if (recursive) { listChildren(child, recursive, prefix + " "); } } else { System.out.println(); } } }
Example 2
Source File: S3CommonFileObject.java From hop with Apache License 2.0 | 6 votes |
protected void doDelete( String key, String bucketName ) throws FileSystemException { // can only delete folder if empty if ( getType() == FileType.FOLDER ) { // list all children inside the folder ObjectListing ol = fileSystem.getS3Client().listObjects( bucketName, key ); ArrayList<S3ObjectSummary> allSummaries = new ArrayList<>( ol.getObjectSummaries() ); // get full list while ( ol.isTruncated() ) { ol = fileSystem.getS3Client().listNextBatchOfObjects( ol ); allSummaries.addAll( ol.getObjectSummaries() ); } for ( S3ObjectSummary s3os : allSummaries ) { fileSystem.getS3Client().deleteObject( bucketName, s3os.getKey() ); } } fileSystem.getS3Client().deleteObject( bucketName, key ); }
Example 3
Source File: SFTPClient.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public FileType getFileType( String filename ) throws KettleJobException { try { SftpATTRS attrs = c.stat( filename ); if ( attrs == null ) { return FileType.IMAGINARY; } if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) { throw new KettleJobException( "Unknown permissions error" ); } if ( attrs.isDir() ) { return FileType.FOLDER; } else { return FileType.FILE; } } catch ( Exception e ) { throw new KettleJobException( e ); } }
Example 4
Source File: SftpClient.java From hop with Apache License 2.0 | 6 votes |
public FileType getFileType( String filename ) throws HopWorkflowException { try { SftpATTRS attrs = c.stat( filename ); if ( attrs == null ) { return FileType.IMAGINARY; } if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) { throw new HopWorkflowException( "Unknown permissions error" ); } if ( attrs.isDir() ) { return FileType.FOLDER; } else { return FileType.FILE; } } catch ( Exception e ) { throw new HopWorkflowException( e ); } }
Example 5
Source File: VfsResource.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Get a list of direct descendants of the given resource. Note that attempts to get a list of * children does <em>not</em> result in an error. Instead an error message is * logged and an empty ArrayList returned. * * @return A <code>ArrayList</code> of VFSResources */ public List<String> getChildren() { init(); List<String> list = new ArrayList<>(); try { if (resourceImpl != null && resourceImpl.exists() && resourceImpl.getType() == FileType.FOLDER) { for (FileObject child : resourceImpl.getChildren()) { list.add(normalize(child.getName().getURI())); } } } catch (IOException e) { Message.debug(e); Message.verbose(e.getLocalizedMessage()); } return list; }
Example 6
Source File: BasicFileSelector.java From obevo with Apache License 2.0 | 5 votes |
@Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception { if (fileInfo.getFile().getType() == FileType.FOLDER && fileInfo.getDepth() == 0) { return true; } else if (this.directoryFilter != null) { return this.directoryFilter.accept(fileInfo); } else { return this.traverseDescendents; } }
Example 7
Source File: DelegateFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of the file, returns null if the file does not exist. */ @Override protected FileType doGetType() throws FileSystemException { if (file != null) { return file.getType(); } else if (children.size() > 0) { return FileType.FOLDER; } else { return FileType.IMAGINARY; } }
Example 8
Source File: RepositoryTreeModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns the number of children of <code>parent</code>. Returns 0 if the node is a leaf or if it has no children. * <code>parent</code> must be a node previously obtained from this data source. * * @param parent * a node in the tree, obtained from this data source * @return the number of children of the node <code>parent</code> */ public int getChildCount( Object parent ) { if ( parent instanceof RepositoryTreeRoot ) { final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent; parent = root1.getRoot(); if ( parent == null ) { return 0; } } try { final FileObject parElement = (FileObject) parent; if ( parElement.getType() != FileType.FOLDER ) { return 0; } final FileObject[] children = parElement.getChildren(); int count = 0; for ( int i = 0; i < children.length; i++ ) { final FileObject child = children[i]; if ( isShowFoldersOnly() && child.getType() != FileType.FOLDER ) { continue; } if ( isShowHiddenFiles() == false && child.isHidden() ) { continue; } if ( child.getType() != FileType.FOLDER && PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) { continue; } count += 1; } return count; } catch ( FileSystemException fse ) { logger.debug( "Failed", fse ); return 0; } }
Example 9
Source File: HdfsFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * @see org.apache.commons.vfs2.provider.AbstractFileObject#doListChildrenResolved() */ @Override protected FileObject[] doListChildrenResolved() throws Exception { if (this.doGetType() != FileType.FOLDER) { return null; } final String[] children = doListChildren(); final FileObject[] fo = new FileObject[children.length]; for (int i = 0; i < children.length; i++) { final Path p = new Path(this.path, children[i]); fo[i] = this.fs.resolveFile(p.toUri().toString()); } return fo; }
Example 10
Source File: TarFileProvider.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates a layered file system. This method is called if the file system is not cached. * * @param scheme The URI scheme. * @param file The file to create the file system on top of. * @return The file system. */ @Override protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new TarFileSystem(rootName, file, fileSystemOptions); }
Example 11
Source File: RepositoryTreeModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public static FileObject findNodeByName( final FileObject node, final String name ) throws FileSystemException { if ( node.getType() != FileType.FOLDER ) { return null; } final FileObject child = node.getChild( name ); if ( child == null ) { return null; } return child; }
Example 12
Source File: VFSClassloaderUtil.java From metron with Apache License 2.0 | 5 votes |
/** * Resolve a set of URIs into FileObject objects. * This is not recursive. The URIs can refer directly to a file or directory or an optional regex at the end. * (NOTE: This is NOT a glob). * @param vfs The file system manager to use to resolve URIs * @param uris comma separated URIs and URI + globs * @return * @throws FileSystemException */ static FileObject[] resolve(FileSystemManager vfs, String uris) throws FileSystemException { if (uris == null) { return new FileObject[0]; } ArrayList<FileObject> classpath = new ArrayList<>(); for (String path : uris.split(",")) { path = path.trim(); if (path.equals("")) { continue; } FileObject fo = vfs.resolveFile(path); switch (fo.getType()) { case FILE: case FOLDER: classpath.add(fo); break; case IMAGINARY: // assume its a pattern String pattern = fo.getName().getBaseName(); if (fo.getParent() != null && fo.getParent().getType() == FileType.FOLDER) { FileObject[] children = fo.getParent().getChildren(); for (FileObject child : children) { if (child.getType() == FileType.FILE && child.getName().getBaseName().matches(pattern)) { classpath.add(child); } } } else { LOG.warn("ignoring classpath entry {}", fo); } break; default: LOG.warn("ignoring classpath entry {}", fo); break; } } return classpath.toArray(new FileObject[classpath.size()]); }
Example 13
Source File: AbstractFileName.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * 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; }
Example 14
Source File: S3NFileNameTest.java From hop with Apache License 2.0 | 4 votes |
@Before public void setup() { fileName = new S3NFileName( SCHEME, "", "", FileType.FOLDER ); }
Example 15
Source File: ActionGetPOP.java From hop with Apache License 2.0 | 4 votes |
String createOutputDirectory( int folderType ) throws HopException, FileSystemException, IllegalArgumentException { if ( ( folderType != ActionGetPOP.FOLDER_OUTPUT ) && ( folderType != ActionGetPOP.FOLDER_ATTACHMENTS ) ) { throw new IllegalArgumentException( "Invalid folderType argument" ); } String folderName = ""; switch ( folderType ) { case ActionGetPOP.FOLDER_OUTPUT: folderName = getRealOutputDirectory(); break; case ActionGetPOP.FOLDER_ATTACHMENTS: if ( isSaveAttachment() && isDifferentFolderForAttachment() ) { folderName = getRealAttachmentFolder(); } else { folderName = getRealOutputDirectory(); } break; } if ( Utils.isEmpty( folderName ) ) { switch ( folderType ) { case ActionGetPOP.FOLDER_OUTPUT: throw new HopException( BaseMessages .getString( PKG, "JobGetMailsFromPOP.Error.OutputFolderEmpty" ) ); case ActionGetPOP.FOLDER_ATTACHMENTS: throw new HopException( BaseMessages .getString( PKG, "JobGetMailsFromPOP.Error.AttachmentFolderEmpty" ) ); } } FileObject folder = HopVfs.getFileObject( folderName ); if ( folder.exists() ) { if ( folder.getType() != FileType.FOLDER ) { switch ( folderType ) { case ActionGetPOP.FOLDER_OUTPUT: throw new HopException( BaseMessages.getString( PKG, "JobGetMailsFromPOP.Error.NotAFolderNot", folderName ) ); case ActionGetPOP.FOLDER_ATTACHMENTS: throw new HopException( BaseMessages.getString( PKG, "JobGetMailsFromPOP.Error.AttachmentFolderNotAFolder", folderName ) ); } } if ( isDebug() ) { switch ( folderType ) { case ActionGetPOP.FOLDER_OUTPUT: logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.Log.OutputFolderExists", folderName ) ); break; case ActionGetPOP.FOLDER_ATTACHMENTS: logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.Log.AttachmentFolderExists", folderName ) ); break; } } } else { if ( isCreateLocalFolder() ) { folder.createFolder(); } else { switch ( folderType ) { case ActionGetPOP.FOLDER_OUTPUT: throw new HopException( BaseMessages.getString( PKG, "JobGetMailsFromPOP.Error.OutputFolderNotExist", folderName ) ); case ActionGetPOP.FOLDER_ATTACHMENTS: throw new HopException( BaseMessages.getString( PKG, "JobGetMailsFromPOP.Error.AttachmentFolderNotExist", folderName ) ); } } } String returnValue = HopVfs.getFilename( folder ); try { folder.close(); } catch ( IOException ignore ) { //Ignore error, as the folder was created successfully } return returnValue; }
Example 16
Source File: RepositoryTreeModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Returns the index of child in parent. If either <code>parent</code> or <code>child</code> is <code>null</code>, * returns -1. If either <code>parent</code> or <code>child</code> don't belong to this tree model, returns -1. * * @param parent * a note in the tree, obtained from this data source * @param childNode * the node we are interested in * @return the index of the child in the parent, or -1 if either <code>child</code> or <code>parent</code> are * <code>null</code> or don't belong to this tree model */ public int getIndexOfChild( Object parent, final Object childNode ) { if ( parent instanceof RepositoryTreeRoot ) { final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent; parent = root1.getRoot(); if ( parent == null ) { return -1; } } try { final FileObject parChild = (FileObject) childNode; final FileObject parElement = (FileObject) parent; final FileObject[] childs = parElement.getChildren(); int count = 0; for ( int i = 0; i < childs.length; i++ ) { final FileObject child = childs[i]; if ( isShowFoldersOnly() && child.getType() != FileType.FOLDER ) { continue; } if ( isShowHiddenFiles() == false && child.isHidden() ) { continue; } if ( child.getType() != FileType.FOLDER && PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) { continue; } if ( child.getName().equals( parChild.getName() ) ) { return count; } count += 1; } return -1; } catch ( FileSystemException fse ) { logger.debug( "Failed", fse ); return -1; } }
Example 17
Source File: ActionCheckFilesLocked.java From hop with Apache License 2.0 | 4 votes |
private void ProcessFile( String filename, String wildcard ) { FileObject filefolder = null; String realFilefoldername = environmentSubstitute( filename ); String realwilcard = environmentSubstitute( wildcard ); try { filefolder = HopVfs.getFileObject( realFilefoldername ); FileObject[] files = new FileObject[] { filefolder }; if ( filefolder.exists() ) { // the file or folder exists if ( filefolder.getType() == FileType.FOLDER ) { // It's a folder if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "ActionCheckFilesLocked.ProcessingFolder", realFilefoldername ) ); } // Retrieve all files files = filefolder.findFiles( new TextFileSelector( filefolder.toString(), realwilcard ) ); if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "ActionCheckFilesLocked.TotalFilesToCheck", String .valueOf( files.length ) ) ); } } else { // It's a file if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "ActionCheckFilesLocked.ProcessingFile", realFilefoldername ) ); } } // Check files locked checkFilesLocked( files ); } else { // We can not find thsi file logBasic( BaseMessages.getString( PKG, "ActionCheckFilesLocked.FileNotExist", realFilefoldername ) ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "ActionCheckFilesLocked.CouldNotProcess", realFilefoldername, e .getMessage() ) ); } finally { if ( filefolder != null ) { try { filefolder.close(); } catch ( IOException ex ) { // Ignore } } } }
Example 18
Source File: JobEntryDeleteFolders.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private boolean deleteFolder( String foldername ) { boolean rcode = false; FileObject filefolder = null; try { filefolder = KettleVFS.getFileObject( foldername, this ); if ( filefolder.exists() ) { // the file or folder exists if ( filefolder.getType() == FileType.FOLDER ) { // It's a folder if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteFolders.ProcessingFolder", foldername ) ); } // Delete Files int Nr = filefolder.delete( new TextFileSelector() ); if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteFolders.TotalDeleted", foldername, String .valueOf( Nr ) ) ); } rcode = true; } else { // Error...This file is not a folder! logError( BaseMessages.getString( PKG, "JobEntryDeleteFolders.Error.NotFolder" ) ); } } else { // File already deleted, no reason to try to delete it if ( log.isBasic() ) { logBasic( BaseMessages.getString( PKG, "JobEntryDeleteFolders.FolderAlreadyDeleted", foldername ) ); } rcode = true; } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "JobEntryDeleteFolders.CouldNotDelete", foldername, e.getMessage() ), e ); } finally { if ( filefolder != null ) { try { filefolder.close(); } catch ( IOException ex ) { // Ignore } } } return rcode; }
Example 19
Source File: VirtualFileProvider.java From commons-vfs with Apache License 2.0 | 3 votes |
/** * Creates an empty virtual file system. * * @param rootUri The root of the file system. * @return A FileObject in the FileSystem. * @throws FileSystemException if an error occurs. */ public FileObject createFileSystem(final String rootUri) throws FileSystemException { final AbstractFileName rootName = new VirtualFileName(rootUri, FileName.ROOT_PATH, FileType.FOLDER); final VirtualFileSystem fs = new VirtualFileSystem(rootName, null); addComponent(fs); return fs.getRoot(); }
Example 20
Source File: ZipFileProvider.java From commons-vfs with Apache License 2.0 | 3 votes |
/** * Creates a layered file system. This method is called if the file system is * not cached. * * @param scheme The URI scheme. * @param file The file to create the file system on top of. * @return The file system. */ @Override protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new ZipFileSystem(rootName, file, fileSystemOptions); }