@Override public boolean includeFile( FileSelectInfo fileSelectInfo ) throws Exception { FileObject file = fileSelectInfo.getFile(); return file.isFile() && file.toString().endsWith( ".jar" ); } } );
/** * Lists all content entities stored in this content-location. This method filters out all files that have an invalid * name (according to the repository rules). * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { try { final FileObject file = getBackend(); final FileObject[] files = file.getChildren(); final ContentEntity[] entities = new ContentEntity[files.length]; for ( int i = 0; i < files.length; i++ ) { final FileObject child = files[i]; if ( RepositoryUtilities.isInvalidPathName( child.getPublicURIString() ) ) { continue; } if ( child.isFolder() ) { entities[i] = new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { entities[i] = new FileObjectContentLocation( this, child ); } } return entities; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
/** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry( final String name ) throws ContentIOException { try { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); if ( child.exists() == false ) { throw new ContentIOException( "Not found:" + child ); } if ( child.isFolder() ) { return new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { return new FileObjectContentItem( this, child ); } else { throw new ContentIOException( "Not File nor directory." ); } } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
@Override public boolean isFile() throws FileSystemException { return decoratedFileObject.isFile(); }
@Override public boolean isFile() throws FileSystemException { return decoratedFileObject.isFile(); }
@Override public boolean isFile() throws FileSystemException { return decoratedFileObject.isFile(); }
@Override public boolean isFile() throws FileSystemException { return decoratedFileObject.isFile(); }
@Override public boolean isFile(String path) throws FileSystemException { try { final FileObject fo = resolveFileObject(path); return fo.isFile(); } catch (org.apache.commons.vfs2.FileSystemException e) { final String msg = "Failed to check if it is a file at " + path + "."; log.debug(msg, e); throw new FileSystemException(msg, e); } }
@Override public String[] listFiles(String folderPath) throws FileSystemException { try { final FileObject fo = resolveFileObject(folderPath); final List<String> entries = new LinkedList<>(); for (FileObject child : fo.getChildren()) { if (child.isFile()) { entries.add(child.getName().getBaseName()); } } return entries.toArray(new String[entries.size()]); } catch (org.apache.commons.vfs2.FileSystemException e) { final String msg = "Failed to list child files of the folder at " + folderPath + "."; log.debug(msg, e); throw new FileSystemException(msg, e); } }
@Override public void deleteFile(String filePath) throws FileSystemException { try { final FileObject fo = resolveFileObject(filePath); if (!fo.isFile()) { throw new FileSystemException("File doesn't exist at " + filePath + "."); } fo.delete(); } catch (org.apache.commons.vfs2.FileSystemException e) { final String msg = "Failed to delete file at " + filePath; log.debug(msg, e); throw new FileSystemException(msg, e); } }
/** * Tests that input streams are cleaned up on file close. */ public void testInputStreamSingleCleanup() throws Exception { // Get the test file final FileObject file = getReadFolder().resolveFile("file1.txt"); assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Open some input streams final InputStream instr1 = file.getContent().getInputStream(); assertTrue(instr1.read() == FILE1_CONTENT.charAt(0)); // Close the file file.close(); // Check assertTrue(instr1.read() == -1); } }
/** * Tests that input streams are cleaned up on file close. */ public void testInputStreamSingleCleanup() throws Exception { // Get the test file final FileObject file = getReadFolder().resolveFile("file1.txt"); assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Open some input streams final InputStream instr1 = file.getContent().getInputStream(); assertTrue(instr1.read() == FILE1_CONTENT.charAt(0)); // Close the file file.close(); // Check assertTrue(instr1.read() == -1); } }
/** * Tests that input streams are cleaned up on file close. */ public void testInputStreamSingleCleanup() throws Exception { // Get the test file final FileObject file = getReadFolder().resolveFile("file1.txt"); assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Open some input streams final InputStream instr1 = file.getContent().getInputStream(); assertTrue(instr1.read() == FILE1_CONTENT.charAt(0)); // Close the file file.close(); // Check assertTrue(instr1.read() == -1); } }
/** * Tests that content and file objects are usable after being closed. */ public void testReuse() throws Exception { // Get the test file final FileObject file = getReadFolder().resolveFile("file1.txt"); assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Get the file content assertSameContent(FILE1_CONTENT, file); // Read the content again assertSameContent(FILE1_CONTENT, file); // Close the content + file file.getContent().close(); file.close(); // Read the content again assertSameContent(FILE1_CONTENT, file); }
/** * Tests that content and file objects are usable after being closed. */ public void testReuse() throws Exception { // Get the test file final FileObject file = getReadFolder().resolveFile("file1.txt"); assertEquals(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Get the file content assertSameContent(FILE1_CONTENT, file); // Read the content again assertSameContent(FILE1_CONTENT, file); // Close the content + file file.getContent().close(); file.close(); // Read the content again assertSameContent(FILE1_CONTENT, file); }
private void check(final FileSystemManager manager, FileObject file) throws FileSystemException { assertNotNull(file); assertTrue(file.exists()); assertSame(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Expand it file = manager.createFileSystem(file); assertNotNull(file); assertTrue(file.exists()); assertSame(FileType.FOLDER, file.getType()); assertTrue(file.isFolder()); }
/** * Tests type determination. */ public void testType() throws Exception { // Test a file FileObject file = resolveFile1Txt(); assertSame(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Test a folder file = getReadFolderDir1(); assertSame(FileType.FOLDER, file.getType()); assertTrue(file.isFolder()); // Test an unknown file file = getReadFolder().resolveFile("unknown-child"); assertSame(FileType.IMAGINARY, file.getType()); }
private void check(final FileSystemManager manager, FileObject file) throws FileSystemException { assertNotNull(file); assertTrue(file.exists()); assertSame(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Expand it file = manager.createFileSystem(file); assertNotNull(file); assertTrue(file.exists()); assertSame(FileType.FOLDER, file.getType()); assertTrue(file.isFolder()); }
/** * Tests type determination. */ public void testType() throws Exception { // Test a file FileObject file = resolveFile1Txt(); assertSame(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Test a folder file = getReadFolderDir1(); assertSame(FileType.FOLDER, file.getType()); assertTrue(file.isFolder()); // Test an unknown file file = getReadFolder().resolveFile("unknown-child"); assertSame(FileType.IMAGINARY, file.getType()); }
/** * Tests type determination. */ public void testType() throws Exception { // Test a file FileObject file = resolveFile1Txt(); assertSame(FileType.FILE, file.getType()); assertTrue(file.isFile()); // Test a folder file = getReadFolderDir1(); assertSame(FileType.FOLDER, file.getType()); assertTrue(file.isFolder()); // Test an unknown file file = getReadFolder().resolveFile("unknown-child"); assertSame(FileType.IMAGINARY, file.getType()); }