org.apache.commons.vfs2.FileType Java Examples
The following examples show how to use
org.apache.commons.vfs2.FileType.
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: RepositoryTreeModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testGetChildCount() { RepositoryTreeModel treeModel = new RepositoryTreeModel(); assertNotNull( treeModel ); treeModel.setFileSystemRoot( repositoryRoot ); assertEquals( 0, treeModel.getChildCount( repositoryRoot ) ); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn( childFiles ).when( repositoryRoot ).getChildren(); doReturn( FileType.FOLDER ).when( repositoryRoot ).getType(); doReturn( FileType.FOLDER ).when( childFile1 ).getType(); doReturn( FileType.FOLDER ).when( childFile2 ).getType(); doReturn( FileType.FOLDER ).when( childFile3 ).getType(); } catch ( FileSystemException e ) { e.printStackTrace(); } assertEquals( 3, treeModel.getChildCount( repositoryRoot ) ); }
Example #2
Source File: Mail.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public boolean includeFile( FileSelectInfo info ) { boolean returncode = false; try { if ( !info.getFile().toString().equals( sourceFolder ) ) { // Pass over the Base folder itself String short_filename = info.getFile().getName().getBaseName(); if ( info.getFile().getParent().equals( info.getBaseFolder() ) || ( ( !info.getFile().getParent().equals( info.getBaseFolder() ) && meta.isIncludeSubFolders() ) ) ) { if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null ) || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard( short_filename, fileWildcard ) ) ) { returncode = true; } } } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "Mail.Error.FindingFiles", info.getFile().toString(), e .getMessage() ) ); returncode = false; } return returncode; }
Example #3
Source File: S3NFileObjectTest.java From hop with Apache License 2.0 | 6 votes |
@Test public void testHandleAttachExceptionFileNotFound() throws FileSystemException { AmazonS3Exception notFoundException = new AmazonS3Exception( "404 Not Found" ); notFoundException.setErrorCode( "404 Not Found" ); AmazonS3Exception noSuchKeyException = new AmazonS3Exception( "NoSuchKey" ); noSuchKeyException.setErrorCode( "NoSuchKey" ); //test the case where the file is not found; no exception should be thrown when( s3ServiceMock.getObject( BUCKET_NAME, origKey ) ).thenThrow( notFoundException ); when( s3ServiceMock.getObject( BUCKET_NAME, origKey + "/" ) ).thenThrow( noSuchKeyException ); childObjectListing = mock( ObjectListing.class ); when( childObjectListing.getObjectSummaries() ).thenReturn( new ArrayList<>() ); when( childObjectListing.getCommonPrefixes() ).thenReturn( new ArrayList<>() ); when( s3ServiceMock.listObjects( any( ListObjectsRequest.class ) ) ).thenReturn( childObjectListing ); try { s3FileObjectFileSpy.doAttach(); } catch ( Exception e ) { fail( "Caught exception " + e.getMessage() ); } assertEquals( FileType.IMAGINARY, s3FileObjectFileSpy.getType() ); }
Example #4
Source File: S3FileNameParser.java From hop with Apache License 2.0 | 6 votes |
public FileName parseUri( VfsComponentContext context, FileName base, String uri ) throws FileSystemException { StringBuilder name = new StringBuilder(); String scheme = UriParser.extractScheme( uri, name ); UriParser.canonicalizePath( name, 0, name.length(), this ); // Normalize separators in the path UriParser.fixSeparators( name ); // Normalise the path FileType fileType = UriParser.normalisePath( name ); String fullPath = name.toString(); // Extract bucket name final String bucketName = UriParser.extractFirstElement( name ); return new S3FileName( scheme, bucketName, fullPath, fileType ); }
Example #5
Source File: FtpFileObject.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Returns the file's list of children. * * @return The list of children * @throws FileSystemException If there was a problem listing children * @see AbstractFileObject#getChildren() * @since 2.0 */ @Override public FileObject[] getChildren() throws FileSystemException { try { if (doGetType() != FileType.FOLDER) { throw new FileNotFolderException(getName()); } } catch (final Exception ex) { throw new FileNotFolderException(getName(), ex); } try { /* * Wrap our parent implementation, noting that we're refreshing so that we don't refresh() ourselves and * each of our parents for each children. Note that refresh() will list children. Meaning, if if this file * has C children, P parents, there will be (C * P) listings made with (C * (P + 1)) refreshes, when there * should really only be 1 listing and C refreshes. */ this.inRefresh.set(true); return super.getChildren(); } finally { this.inRefresh.set(false); } }
Example #6
Source File: S3CommonFileObject.java From hop with Apache License 2.0 | 6 votes |
private void handleAttachExceptionFallback( String bucket, String keyWithDelimiter, AmazonS3Exception exception ) throws FileSystemException { ListObjectsRequest listObjectsRequest = new ListObjectsRequest() .withBucketName( bucket ) .withPrefix( keyWithDelimiter ) .withDelimiter( DELIMITER ); ObjectListing ol = fileSystem.getS3Client().listObjects( listObjectsRequest ); if ( !( ol.getCommonPrefixes().isEmpty() && ol.getObjectSummaries().isEmpty() ) ) { injectType( FileType.FOLDER ); } else { //Folders don't really exist - they will generate a "NoSuchKey" exception // confirms key doesn't exist but connection okay String errorCode = exception.getErrorCode(); if ( !errorCode.equals( "NoSuchKey" ) ) { // bubbling up other connection errors logger.error( "Could not get information on " + getQualifiedName(), exception ); // make sure this gets printed for the user throw new FileSystemException( "vfs.provider/get-type.error", getQualifiedName(), exception ); } } }
Example #7
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Called when this file is deleted. Updates cached info and notifies subclasses, parent and file system. * * @throws Exception if an error occurs. */ protected void handleDelete() throws Exception { synchronized (fileSystem) { if (attached) { // Fix up state injectType(FileType.IMAGINARY); removeChildrenCache(); // Notify subclass onChange(); } // Notify parent that its child list may no longer be valid notifyParent(this.getName(), FileType.IMAGINARY); // Notify the file system fileSystem.fireFileDeleted(this); } }
Example #8
Source File: RepositoryTableModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testGetElementForRow() { RepositoryTableModel repoTableModel = new RepositoryTableModel(); assertNotNull( repoTableModel ); repoTableModel.setSelectedPath( fileObject ); try { doReturn( FileType.FOLDER ).when( fileObject ).getType(); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; doReturn( childFileName1 ).when( childFile1 ).getName(); doReturn( childFileName2 ).when( childFile2 ).getName(); doReturn( childFileName3 ).when( childFile3 ).getName(); doReturn( "file1.txt" ).when( childFileName1 ).getBaseName(); doReturn( "file2.txt" ).when( childFileName2 ).getBaseName(); doReturn( "file3.txt" ).when( childFileName3 ).getBaseName(); doReturn( childFiles ).when( fileObject ).getChildren(); assertEquals( childFile2, repoTableModel.getElementForRow( 1 ) ); } catch ( FileSystemException e ) { e.printStackTrace(); } }
Example #9
Source File: S3FileObjectTest.java From hop with Apache License 2.0 | 6 votes |
@Test public void testDoRename() throws Exception { String someNewBucketName = "someNewBucketName"; String someNewKey = "some/newKey"; S3FileName newFileName = new S3FileName( SCHEME, someNewBucketName, someNewBucketName + "/" + someNewKey, FileType.FILE ); S3FileObject newFile = new S3FileObject( newFileName, fileSystemSpy ); ArgumentCaptor<CopyObjectRequest> copyObjectRequestArgumentCaptor = ArgumentCaptor.forClass( CopyObjectRequest.class ); when( s3ServiceMock.doesBucketExistV2( someNewBucketName ) ).thenReturn( true ); s3FileObjectFileSpy.doAttach(); s3FileObjectFileSpy.moveTo( newFile ); verify( s3ServiceMock ).copyObject( copyObjectRequestArgumentCaptor.capture() ); assertEquals( someNewBucketName, copyObjectRequestArgumentCaptor.getValue().getDestinationBucketName() ); assertEquals( someNewKey, copyObjectRequestArgumentCaptor.getValue().getDestinationKey() ); assertEquals( BUCKET_NAME, copyObjectRequestArgumentCaptor.getValue().getSourceBucketName() ); assertEquals( origKey, copyObjectRequestArgumentCaptor.getValue().getSourceKey() ); }
Example #10
Source File: S3FileObjectTest.java From hop with Apache License 2.0 | 6 votes |
@Test public void testHandleAttachExceptionEmptyFolder() throws FileSystemException { String testKey = BUCKET_NAME + "/" + origKey; String testBucket = "badBucketName"; AmazonS3Exception exception = new AmazonS3Exception( "NoSuchKey" ); exception.setErrorCode( "NoSuchKey" ); //test the case where the folder exists and contains things; no exception should be thrown when( s3ServiceMock.getObject( BUCKET_NAME, origKey + "/" ) ).thenThrow( exception ); childObjectListing = mock( ObjectListing.class ); when( childObjectListing.getObjectSummaries() ).thenReturn( new ArrayList<>() ); when( childObjectListing.getCommonPrefixes() ).thenReturn( new ArrayList<>() ); when( s3ServiceMock.listObjects( any( ListObjectsRequest.class ) ) ).thenReturn( childObjectListing ); try { s3FileObjectFileSpy.handleAttachException( testKey, testBucket ); } catch ( FileSystemException e ) { fail( "Caught exception " + e.getMessage() ); } assertEquals( FileType.IMAGINARY, s3FileObjectFileSpy.getType() ); }
Example #11
Source File: ContentTests.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Tests existence determination. */ public void testExists() throws Exception { // Test a file FileObject file = getReadFolder().resolveFile("file1.txt"); assertTrue("file exists", file.exists()); assertNotSame("file exists", file.getType(), FileType.IMAGINARY); // Test a folder file = getReadFolder().resolveFile("dir1"); assertTrue("folder exists", file.exists()); assertNotSame("folder exists", file.getType(), FileType.IMAGINARY); // Test an unknown file file = getReadFolder().resolveFile("unknown-child"); assertFalse("unknown file does not exist", file.exists()); assertSame("unknown file does not exist", file.getType(), FileType.IMAGINARY); // Test an unknown file in an unknown folder file = getReadFolder().resolveFile("unknown-folder/unknown-child"); assertFalse("unknown file does not exist", file.exists()); assertSame("unknown file does not exist", file.getType(), FileType.IMAGINARY); }
Example #12
Source File: JobEntryCheckFilesLocked.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void processFile( String filename, String wildcard ) { String realFileFolderName = environmentSubstitute( filename ); String realWildcard = environmentSubstitute( wildcard ); try ( FileObject fileFolder = KettleVFS.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, "JobEntryCheckFilesLocked.ProcessingFolder", realFileFolderName ) ); } // Retrieve all files files = fileFolder.findFiles( new TextFileSelector( fileFolder.toString(), realWildcard ) ); if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobEntryCheckFilesLocked.TotalFilesToCheck", String .valueOf( files.length ) ) ); } } else { // It's a file if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobEntryCheckFilesLocked.ProcessingFile", realFileFolderName ) ); } } // Check files locked checkFilesLocked( files ); } else { // We can not find thsi file logBasic( BaseMessages.getString( PKG, "JobEntryCheckFilesLocked.FileNotExist", realFileFolderName ) ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "JobEntryCheckFilesLocked.CouldNotProcess", realFileFolderName, e .getMessage() ) ); } }
Example #13
Source File: KettleFileRepository.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public List<RepositoryElementMetaInterface> getJobObjects( ObjectId id_directory, boolean includeDeleted ) throws KettleException { try { List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory( id_directory ); String folderName = calcDirectoryName( directory ); FileObject folder = KettleVFS.getFileObject( folderName ); for ( FileObject child : folder.getChildren() ) { if ( child.getType().equals( FileType.FILE ) ) { if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) { String name = child.getName().getBaseName(); if ( name.endsWith( EXT_JOB ) ) { String jobName = name.substring( 0, name.length() - 4 ); ObjectId id = new StringObjectId( calcObjectId( directory, jobName, EXT_JOB ) ); Date date = new Date( child.getContent().getLastModifiedTime() ); list.add( new RepositoryObject( id, jobName, directory, "-", date, RepositoryObjectType.JOB, "", false ) ); } } } } return list; } catch ( Exception e ) { throw new KettleException( "Unable to get list of jobs in folder with id : " + id_directory, e ); } }
Example #14
Source File: RepositoryOpenDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public String performOpen( final AuthenticationData loginData, final String previousSelection ) throws FileSystemException, UnsupportedEncodingException { fileSystemRoot = PublishUtil.createVFSConnection( VFS.getManager(), loginData ); if ( previousSelection == null ) { setSelectedView( fileSystemRoot ); } else { final FileObject view = fileSystemRoot.resolveFile( previousSelection ); if ( view == null ) { setSelectedView( fileSystemRoot ); } else { if ( view.exists() == false ) { setSelectedView( fileSystemRoot ); } else if ( view.getType() == FileType.FOLDER ) { setSelectedView( view ); } else { setSelectedView( view.getParent() ); } } } if ( StringUtils.isEmpty( fileNameTextField.getText(), true ) && previousSelection != null ) { final String fileName = IOUtils.getInstance().getFileName( previousSelection ); DebugLog.log( "Setting filename to " + fileName ); fileNameTextField.setText( fileName ); } getConfirmAction().setEnabled( validateInputs( false ) ); if ( super.performEdit() == false || selectedView == null ) { return null; } return getSelectedFile(); }
Example #15
Source File: FileObject.java From obevo with Apache License 2.0 | 5 votes |
@Override public FileType getType() { try { return this.fileObject.getType(); } catch (FileSystemException e) { throw new VFSFileSystemException(e); } }
Example #16
Source File: S3AFileName.java From hop with Apache License 2.0 | 5 votes |
public S3AFileName( String scheme, String bucketId, String path, FileType type ) { super( scheme, path, type ); this.bucketId = bucketId; if ( path.length() > 1 ) { this.bucketRelativePath = path.substring( 1 ); if ( type.equals( FileType.FOLDER ) ) { this.bucketRelativePath += DELIMITER; } } else { this.bucketRelativePath = ""; } }
Example #17
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 #18
Source File: HttpFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive. */ @Override protected FileType doGetType() throws Exception { // Use the HEAD method to probe the file. final int status = this.getHeadMethod().getStatusCode(); if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) { return FileType.FILE; } else if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { return FileType.IMAGINARY; } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } }
Example #19
Source File: S3NFileObjectTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testDoGetTypeFolder() throws Exception { FileName mockFile = mock( FileName.class ); when( s3FileObjectBucketSpy.getName() ).thenReturn( mockFile ); when( mockFile.getPath() ).thenReturn( S3NFileObject.DELIMITER ); assertEquals( FileType.FOLDER, s3FileObjectBucketSpy.getType() ); }
Example #20
Source File: Shell.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Does an 'ls' command. */ private void ls(final String[] cmd) throws FileSystemException { int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mgr.resolveFile(cwd, cmd[pos]); } else { file = cwd; } if (file.getType() == FileType.FOLDER) { // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); } else { // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); } }
Example #21
Source File: KettleFileRepository.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public String[] getJobNames( ObjectId id_directory, boolean includeDeleted ) throws KettleException { try { List<String> list = new ArrayList<String>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory( id_directory ); String folderName = calcDirectoryName( directory ); FileObject folder = KettleVFS.getFileObject( folderName ); for ( FileObject child : folder.getChildren() ) { if ( child.getType().equals( FileType.FILE ) ) { if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) { String name = child.getName().getBaseName(); if ( name.endsWith( EXT_JOB ) ) { String jobName = name.substring( 0, name.length() - 4 ); list.add( jobName ); } } } } return list.toArray( new String[list.size()] ); } catch ( Exception e ) { throw new KettleException( "Unable to get list of transformations names in folder with id : " + id_directory, e ); } }
Example #22
Source File: KettleFileRepository.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public List<RepositoryElementMetaInterface> getTransformationObjects( ObjectId idDirectory, boolean includeDeleted ) throws KettleException { try { List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory( idDirectory ); String folderName = calcDirectoryName( directory ); FileObject folder = KettleVFS.getFileObject( folderName ); for ( FileObject child : folder.getChildren() ) { if ( child.getType().equals( FileType.FILE ) ) { if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) { String name = child.getName().getBaseName(); if ( name.endsWith( EXT_TRANSFORMATION ) ) { String transName = name.substring( 0, name.length() - 4 ); ObjectId id = new StringObjectId( calcObjectId( directory, transName, EXT_TRANSFORMATION ) ); Date date = new Date( child.getContent().getLastModifiedTime() ); list.add( new RepositoryObject( id, transName, directory, "-", date, RepositoryObjectType.TRANSFORMATION, "", false ) ); } } } } return list; } catch ( Exception e ) { throw new KettleException( "Unable to get list of transformations in folder with id : " + idDirectory, e ); } }
Example #23
Source File: PreviewListener.java From otroslogviewer with Apache License 2.0 | 5 votes |
@Override public void valueChanged(ListSelectionEvent listSelectionEvent) { if (listSelectionEvent.getValueIsAdjusting()) { return; } boolean previewEnabled = previewComponent.isPreviewEnabled(); if (!previewEnabled) { return; } FileObject fileObjectToPreview = null; for (FileObject fileObject : vfsBrowser.getSelectedFiles()) { try { if (fileObject.getType().equals(FileType.FILE)) { fileObjectToPreview = fileObject; break; } } catch (FileSystemException e) { LOGGER.error("Can't resolve file", e); } } if (fileObjectToPreview != null) { makePreview(fileObjectToPreview); } else { clearPreview(); } }
Example #24
Source File: S3FileNameTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testAppendRootUriWithNonDefaultPort() { String fooFolder = "FooFolder"; String fooBucket = "FooBucket"; fileName = new S3FileName( SCHEME, DELIMITER, fooFolder, FileType.FOLDER ); String expectedUri = SCHEME + SCHEME_DELIMITER + fooFolder; assertEquals( expectedUri, fileName.getURI() ); fileName = new S3FileName( SCHEME, fooBucket, fooBucket + DELIMITER + fooFolder, FileType.FOLDER ); expectedUri = SCHEME + SCHEME_DELIMITER + fooBucket + DELIMITER + fooFolder; assertEquals( expectedUri, fileName.getURI() ); }
Example #25
Source File: RepositoryOpenDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ public void mouseClicked( final MouseEvent e ) { if ( e.getButton() != 1 ) { return; } if ( e.getClickCount() < 2 ) { return; } final int selectedRowRaw = table.getSelectedRow(); if ( selectedRowRaw == -1 ) { return; } final int selectedRow = table.convertRowIndexToModel( selectedRowRaw ); final FileObject selectedFileObject = table.getSelectedFileObject( selectedRow ); if ( selectedFileObject == null ) { return; } try { if ( FileType.FOLDER.equals( selectedFileObject.getType() ) ) { setSelectedView( selectedFileObject ); } else if ( FileType.FILE.equals( selectedFileObject.getType() ) ) { if ( isDoubleClickConfirmsDialog() == false ) { return; } setConfirmed( true ); setVisible( false ); } } catch ( FileSystemException e1 ) { // ignore .. } }
Example #26
Source File: HdfsFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * @see org.apache.commons.vfs2.provider.AbstractFileObject#doListChildren() */ @Override protected String[] doListChildren() throws Exception { if (this.doGetType() != FileType.FOLDER) { throw new FileNotFolderException(this); } final FileStatus[] files = this.hdfs.listStatus(this.path); final String[] children = new String[files.length]; int i = 0; for (final FileStatus status : files) { children[i++] = status.getPath().getName(); } return children; }
Example #27
Source File: S3FileObjectTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testDoGetTypeFolder() throws Exception { FileName mockFile = mock( FileName.class ); when( s3FileObjectBucketSpy.getName() ).thenReturn( mockFile ); when( mockFile.getPath() ).thenReturn( S3FileObject.DELIMITER ); assertEquals( FileType.FOLDER, s3FileObjectBucketSpy.getType() ); }
Example #28
Source File: ActionFoldersCompare.java From hop with Apache License 2.0 | 5 votes |
public boolean includeFile( FileSelectInfo info ) { boolean returncode = false; try { if ( !info.getFile().toString().equals( source_folder ) ) { // Pass over the Base folder itself String short_filename = info.getFile().getName().getBaseName(); if ( info.getFile().getParent().equals( info.getBaseFolder() ) ) { // In the Base Folder... if ( ( info.getFile().getType() == FileType.FILE && compareonly.equals( "only_files" ) ) || ( info.getFile().getType() == FileType.FOLDER && compareonly.equals( "only_folders" ) ) || ( GetFileWildcard( short_filename ) && compareonly.equals( "specify" ) ) || ( compareonly.equals( "all" ) ) ) { returncode = true; } } else { // Not in the Base Folder...Only if include sub folders if ( includesubfolders ) { if ( ( info.getFile().getType() == FileType.FILE && compareonly.equals( "only_files" ) ) || ( info.getFile().getType() == FileType.FOLDER && compareonly.equals( "only_folders" ) ) || ( GetFileWildcard( short_filename ) && compareonly.equals( "specify" ) ) || ( compareonly.equals( "all" ) ) ) { returncode = true; } } } } } catch ( Exception e ) { logError( "Error while finding files ... in [" + info.getFile().toString() + "]. Exception :" + e.getMessage() ); returncode = false; } return returncode; }
Example #29
Source File: ContentTests.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Tests that input streams are cleaned up on file close. */ public void testByteArrayReadAll() throws Exception { // Get the test file try (final FileObject file = getReadFolder().resolveFile("file1.txt")) { assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); assertEquals(FILE1_CONTENT, new String(file.getContent().getByteArray())); } }
Example #30
Source File: ContentTests.java From commons-vfs with Apache License 2.0 | 5 votes |
public void testGetString_String() throws Exception { // Get the test file try (final FileObject file = getReadFolder().resolveFile("file1.txt")) { assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); assertEquals(FILE1_CONTENT, new String(file.getContent().getString(StandardCharsets.UTF_8.name()))); } }