Java Code Examples for org.apache.commons.vfs2.FileSystemException#printStackTrace()
The following examples show how to use
org.apache.commons.vfs2.FileSystemException#printStackTrace() .
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: RepositoryTableModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testGetRowCount() { RepositoryTableModel repoTableModel = new RepositoryTableModel(); assertNotNull( repoTableModel ); assertEquals( 0, repoTableModel.getRowCount() ); repoTableModel.setSelectedPath( fileObject ); assertEquals( 0, repoTableModel.getRowCount() ); 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( 3, repoTableModel.getRowCount() ); } catch ( FileSystemException e ) { e.printStackTrace(); } }
Example 2
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 3
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 4
Source File: RepositoryTreeModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testGetIndexOfChild() { RepositoryTreeModel treeModel = new RepositoryTreeModel(); assertNotNull( treeModel ); treeModel.setFileSystemRoot( repositoryRoot ); treeModel.setShowFoldersOnly( false ); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn( childFiles ).when( repositoryRoot ).getChildren(); doReturn( childFileName1 ).when( childFile1 ).getName(); doReturn( childFileName2 ).when( childFile2 ).getName(); doReturn( childFileName3 ).when( childFile3 ).getName(); doReturn( "BaseName1" ).when( childFileName1 ).getBaseName(); doReturn( "BaseName2" ).when( childFileName2 ).getBaseName(); doReturn( "BaseName3" ).when( childFileName3 ).getBaseName(); } catch ( FileSystemException e ) { e.printStackTrace(); } assertEquals( 1, treeModel.getIndexOfChild( repositoryRoot, childFile2 ) ); assertEquals( -1, treeModel.getIndexOfChild( repositoryRoot, childFile4 ) ); }
Example 5
Source File: RepositoryTreeModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testGetTreePathForSelection() { RepositoryTreeModel treeModel = new RepositoryTreeModel(); assertNotNull( treeModel ); treeModel.setFileSystemRoot( repositoryRoot ); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn( childFiles ).when( repositoryRoot ).getChildren(); doReturn( childFileName1 ).when( childFile1 ).getName(); doReturn( childFileName2 ).when( childFile2 ).getName(); doReturn( childFileName3 ).when( childFile3 ).getName(); doReturn( repositoryRoot ).when( childFile1 ).getParent(); doReturn( repositoryRoot ).when( childFile2 ).getParent(); doReturn( repositoryRoot ).when( childFile3 ).getParent(); TreePath path = treeModel.getTreePathForSelection( childFile2, null ); assertEquals( 2, path.getPath().length ); assertEquals( childFile2, path.getLastPathComponent() ); } catch ( FileSystemException e ) { e.printStackTrace(); } }
Example 6
Source File: RepositoryTreeModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testFindNodeByName() { FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn( FileType.FOLDER ).when( repositoryRoot ).getType(); doReturn( childFiles ).when( repositoryRoot ).getChildren(); doReturn( childFileName1 ).when( childFile1 ).getName(); doReturn( childFileName2 ).when( childFile2 ).getName(); doReturn( childFileName3 ).when( childFile3 ).getName(); doReturn( "BaseName1" ).when( childFileName1 ).getBaseName(); doReturn( "BaseName2" ).when( childFileName2 ).getBaseName(); doReturn( "BaseName3" ).when( childFileName3 ).getBaseName(); doReturn( childFile2 ).when( repositoryRoot ).getChild( "BaseName2" ); assertEquals( childFile2, RepositoryTreeModel.findNodeByName( repositoryRoot, "BaseName2" ) ); } catch ( FileSystemException e ) { e.printStackTrace(); } }
Example 7
Source File: VFSFileSystem.java From commons-configuration with Apache License 2.0 | 6 votes |
@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; } }
Example 8
Source File: VFSFileSystem.java From commons-configuration with Apache License 2.0 | 6 votes |
@Override public String getFileName(final String path) { if (UriParser.extractScheme(path) == null) { return super.getFileName(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getBaseName(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
Example 9
Source File: SftpUserAuthenticator.java From otroslogviewer with Apache License 2.0 | 5 votes |
@Override protected void getAuthenticationData(UserAuthenticationData authenticationData) { super.getAuthenticationData(authenticationData); authenticationData.setData(UserAuthenticationDataWrapper.SSH_KEY, sshKeyFileField.getText().trim().toCharArray()); if (StringUtils.isNotBlank(sshKeyFileField.getText())) { try { SftpFileSystemConfigBuilder.getInstance().setIdentities(getFileSystemOptions(), new File[]{new File(sshKeyFileField.getText())}); //TODO set user auth data file path } catch (FileSystemException e) { e.printStackTrace(); } } }
Example 10
Source File: KettleVFS.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private KettleVFS() { fsm = new ConcurrentFileSystemManager(); // Forcibly overrides VFS's default StandardFileSystemManager with our Concurrent File System Manager, which will // also allow us to point at our own providers.xml file, instead of the default file that comes with the // commons-vfs2 library. VFS.setManager( fsm ); try { fsm.setFilesCache( new WeakRefFilesCache() ); fsm.init(); } catch ( FileSystemException e ) { e.printStackTrace(); } // Install a shutdown hook to make sure that the file system manager is closed // This will clean up temporary files in vfs_cache Runtime.getRuntime().addShutdownHook( new Thread( new Runnable() { @Override public void run() { if ( fsm != null ) { try { fsm.close(); } catch ( Exception ignored ) { // Exceptions can be thrown due to a closed classloader } } } } ) ); }
Example 11
Source File: RepositoryTableModelTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testGetValueAt() { final String localizedName1 = "fileName1"; final String localizedName2 = "fileName2"; final String localizedName3 = "fileName3"; final String description1 = "description1"; final String description2 = "description2"; final String description3 = "description3"; final long modifiedTime = System.currentTimeMillis(); 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( childFileContent1 ).when( childFile1 ).getContent(); doReturn( childFileContent2 ).when( childFile2 ).getContent(); doReturn( childFileContent3 ).when( childFile3 ).getContent(); doReturn( localizedName1 ).when( childFileContent1 ).getAttribute( "localized-name" ); doReturn( localizedName2 ).when( childFileContent2 ).getAttribute( "localized-name" ); doReturn( localizedName3 ).when( childFileContent3 ).getAttribute( "localized-name" ); doReturn( description1 ).when( childFileContent1 ).getAttribute( "description" ); doReturn( description2 ).when( childFileContent2 ).getAttribute( "description" ); doReturn( description3 ).when( childFileContent3 ).getAttribute( "description" ); doReturn( modifiedTime ).when( childFileContent1 ).getLastModifiedTime(); doReturn( modifiedTime ).when( childFileContent2 ).getLastModifiedTime(); doReturn( modifiedTime ).when( childFileContent3 ).getLastModifiedTime(); doReturn( childFiles ).when( fileObject ).getChildren(); assertEquals( localizedName1, repoTableModel.getValueAt( 0, 0 ) ); assertEquals( "file1.txt", repoTableModel.getValueAt( 0, 1 ) ); assertEquals( new Date( modifiedTime ), repoTableModel.getValueAt( 0, 2 ) ); assertEquals( description1, repoTableModel.getValueAt( 0, 3 ) ); } catch ( FileSystemException e ) { e.printStackTrace(); } }
Example 12
Source File: ShowProperties.java From commons-vfs with Apache License 2.0 | 4 votes |
public static void main(final String[] args) { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return; } for (final String arg : args) { try { final FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + arg); final FileObject file = mgr.resolveFile(arg); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { final FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > SHOW_MAX) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (final FileSystemException ex) { ex.printStackTrace(); } } }