org.apache.commons.vfs2.FileSystemException Java Examples
The following examples show how to use
org.apache.commons.vfs2.FileSystemException.
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: DefaultFileSystemManagerProvider.java From spoofax with Apache License 2.0 | 6 votes |
@Override public FileSystemManager get() { try { final DefaultFileSystemManager manager = new DefaultFileSystemManager(); manager.setFilesCache(new DefaultFilesCache()); manager.setCacheStrategy(CacheStrategy.ON_RESOLVE); final String baseTmpDir = System.getProperty("java.io.tmpdir"); final File tempDir = new File(baseTmpDir, "vfs_cache" + new Random().nextLong()).getAbsoluteFile(); final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir); manager.setTemporaryFileStore(replicator); manager.setReplicator(replicator); addDefaultProvider(manager); addProviders(manager); setBaseFile(manager); manager.init(); return manager; } catch(FileSystemException e) { throw new RuntimeException("Cannot initialize resource service: " + e.getMessage(), e); } }
Example #2
Source File: AgeFileFilterTest.java From commons-vfs with Apache License 2.0 | 6 votes |
@Test public void testAgeFileFilterFileBoolean() throws FileSystemException { AgeFileFilter testee; testee = new AgeFileFilter(currentFileInfo.getFile(), true); Assert.assertTrue(testee.accept(oldFileInfo)); Assert.assertTrue(testee.accept(currentFileInfo)); Assert.assertFalse(testee.accept(newFileInfo)); testee = new AgeFileFilter(currentFileInfo.getFile(), false); Assert.assertFalse(testee.accept(oldFileInfo)); Assert.assertFalse(testee.accept(currentFileInfo)); Assert.assertTrue(testee.accept(newFileInfo)); }
Example #3
Source File: WebdavFileObject.java From commons-vfs with Apache License 2.0 | 6 votes |
DavPropertySet getProperties(final URLFileName name, final int type, final DavPropertyNameSet nameSet, final boolean addEncoding) throws FileSystemException { try { final String urlStr = toUrlString(name); final PropFindMethod method = new PropFindMethod(urlStr, type, nameSet, DavConstants.DEPTH_0); setupMethod(method); execute(method); if (method.succeeded()) { final MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); final MultiStatusResponse response = multiStatus.getResponses()[0]; final DavPropertySet props = response.getProperties(HttpStatus.SC_OK); if (addEncoding) { final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, method.getResponseCharSet()); props.add(prop); } return props; } return new DavPropertySet(); } catch (final FileSystemException fse) { throw fse; } catch (final Exception e) { throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type, nameSet.getContent(), addEncoding); } }
Example #4
Source File: SwtSvgImageUtil.java From hop with Apache License 2.0 | 6 votes |
/** * Internal image loading from Hop's user.dir VFS. */ private static SwtUniversalImage loadFromBasedVFS( Display display, String location ) { try { FileObject imageFileObject = HopVfs.getFileSystemManager().resolveFile( base, location ); InputStream s = HopVfs.getInputStream( imageFileObject ); if ( s == null ) { return null; } try { return loadImage( display, s, location ); } finally { IOUtils.closeQuietly( s ); } } catch ( FileSystemException ex ) { return null; } }
Example #5
Source File: RestDataspaceImpl.java From scheduling with GNU Affero General Public License v3.0 | 6 votes |
private Response deleteDir(FileObject fo, List<String> includes, List<String> excludes) throws FileSystemException { if ((includes == null || includes.isEmpty()) && (excludes == null || excludes.isEmpty())) { fo.delete(SELECT_ALL); fo.delete(); return noContentRes(); } else { List<FileObject> children = FileSystem.findFiles(fo, includes, excludes); for (FileObject child : children) { if (!child.delete()) { child.delete(SELECT_ALL); child.delete(); } } return noContentRes(); } }
Example #6
Source File: GenericURLFileName.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Gets the path encoded suitable for url like file system e.g. (http, webdav). * * @param charset the charset used for the path encoding * @return The encoded path. * @throws URISyntaxException If an error occurs encoding the URI. * @throws FileSystemException If some other error occurs. */ public String getPathQueryEncoded(final String charset) throws URISyntaxException, FileSystemException { if (getQueryString() == null) { if (charset != null) { return URIUtils.encodePath(getPathDecoded(), charset); } else { return URIUtils.encodePath(getPathDecoded()); } } final StringBuilder sb = new StringBuilder(BUFFER_SIZE); if (charset != null) { sb.append(URIUtils.encodePath(getPathDecoded(), charset)); } else { sb.append(URIUtils.encodePath(getPathDecoded())); } sb.append("?"); sb.append(getQueryString()); return sb.toString(); }
Example #7
Source File: FileObjectResourceData.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public FileObjectResourceData( final ResourceKey key ) throws ResourceLoadingException { if ( key == null ) { throw new NullPointerException(); } final FileObject fileObject = (FileObject) key.getIdentifier(); try { if ( fileObject.exists() == false ) { throw new ResourceLoadingException( "File-handle given does not point to an existing file." ); } if ( fileObject.isFile() == false ) { throw new ResourceLoadingException( "File-handle given does not point to a regular file." ); } if ( fileObject.isReadable() == false ) { throw new ResourceLoadingException( "File '" + fileObject + "' is not readable." ); } } catch ( FileSystemException fse ) { throw new ResourceLoadingException( "Unable to create FileObjectResourceData : ", fse ); } this.key = key; this.fileObject = fileObject; }
Example #8
Source File: CommonPaths.java From spoofax with Apache License 2.0 | 6 votes |
@Nullable protected FileObject find(Iterable<FileObject> dirs, String relativePath) { FileObject file = null; for(FileObject dir : dirs) { try { FileObject candidate = dir.resolveFile(relativePath); if(candidate.exists()) { if(file != null) { throw new MetaborgRuntimeException("Found multiple candidates for " + relativePath); } else { file = candidate; } } } catch(FileSystemException e) { logger.warn("Error when trying to resolve {} in {}", e, relativePath, dir); } } return file; }
Example #9
Source File: ResourceService.java From spoofax with Apache License 2.0 | 5 votes |
@Override public FileObject resolve(String uri) { try { final String uriEncoded = URIEncode.encode(uri); return fileSystemManager.resolveFile(uriEncoded, fileSystemOptions); } catch(FileSystemException e) { throw new MetaborgRuntimeException(e); } }
Example #10
Source File: PrefixFileFilterTest.java From commons-vfs with Apache License 2.0 | 5 votes |
@Test public void testAcceptStringIOCaseInsensitive() throws FileSystemException { // PREPARE final PrefixFileFilter filter = new PrefixFileFilter(IOCase.INSENSITIVE, "test"); // TEST Assert.assertTrue(filter.accept(createFileSelectInfo(new File("test1.txt")))); Assert.assertTrue(filter.accept(createFileSelectInfo(new File("test2.txt")))); Assert.assertTrue(filter.accept(createFileSelectInfo(new File("Test2.txt")))); Assert.assertTrue(filter.accept(createFileSelectInfo(new File("test.xxx")))); }
Example #11
Source File: FileObject.java From obevo with Apache License 2.0 | 5 votes |
@Override public void createFile() { try { this.fileObject.createFile(); } catch (FileSystemException e) { throw new VFSFileSystemException(e); } }
Example #12
Source File: ParseXmlInZipTestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
private void testResolveAndParseXmlInZip(final String xmlPathInZip, final String xsdPathInZip) throws IOException, FileSystemException, SAXException { final File newZipFile = createTempFile(); final String zipFilePath = "zip:file:" + newZipFile.getAbsolutePath(); final FileSystemManager manager = VFS.getManager(); try (final FileObject zipFileObject = manager.resolveFile(zipFilePath)) { try (final FileObject xmlFileObject = zipFileObject.resolveFile(xmlPathInZip)) { try (final InputStream inputStream = xmlFileObject.getContent().getInputStream()) { final Document document = newDocumentBuilder(zipFileObject, xmlFileObject, xsdPathInZip) .parse(inputStream); Assert.assertNotNull(document); } } } }
Example #13
Source File: ContentTests.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Tests root of file system exists. */ public void testRootURI() throws FileSystemException { if (!this.getProviderConfig().isFileSystemRootAccessible()) { return; } final FileSystem fileSystem = getFileSystem(); final String uri = fileSystem.getRootURI(); testRoot(getManager().resolveFile(uri, fileSystem.getFileSystemOptions())); }
Example #14
Source File: VFS.java From obevo with Apache License 2.0 | 5 votes |
public FileObject resolveFile(String path) { try { return FileObject.toDaFileObject(org.apache.commons.vfs2.VFS.getManager().resolveFile(path)); } catch (FileSystemException e) { throw new VFSFileSystemException("Cannot find file " + path + ", or tried to resolve a classpath folder that had no files in it", e); } }
Example #15
Source File: FileObjectResourceLoader.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public URL toURL( final ResourceKey key ) { if ( key == null ) { throw new NullPointerException(); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } try { final FileObject fileObject = (FileObject) key.getIdentifier(); return fileObject.getURL(); } catch ( FileSystemException e ) { return null; } }
Example #16
Source File: SyntaxFacet.java From spoofax with Apache License 2.0 | 5 votes |
/** * Checks if the parse table file exists, returns errors if not. * * @throws FileSystemException * When an error occurs while checking if the parse table file exists. * @return Errors, or empty if there are no errors. */ public Iterable<String> available() throws FileSystemException { final Collection<String> errors = Lists.newLinkedList(); if(parseTable != null && !parseTable.exists()) { final String message = logger.format("SDF parse table file {} does not exist", parseTable); errors.add(message); } return errors; }
Example #17
Source File: SchedulerDataspaceImpl.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean isFolder(String dataspace, String pathname) throws NotConnectedException, PermissionException { try { return resolveFile(dataspace, pathname).isFolder(); } catch (FileSystemException e) { logger.debug(String.format("Can't parse the file [%s] in the dataspace [%s].", pathname, dataspace), e); return false; } }
Example #18
Source File: SelectionAdapterFileDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
void setFilename( FileDialogOperation fileDialogOperation, FileObject fileObject ) throws KettleException { try { fileDialogOperation.setFilename( fileObject.isFile() ? fileObject.getName().getBaseName() : null ); } catch ( FileSystemException fse ) { throw new KettleException( "failed to check isFile in setFilename()", fse ); } }
Example #19
Source File: AgeFileFilterTest.java From commons-vfs with Apache License 2.0 | 5 votes |
@Test public void testAgeFileFilterLongBoolean() throws FileSystemException { AgeFileFilter testee; testee = new AgeFileFilter(NOW, true); Assert.assertTrue(testee.accept(oldFileInfo)); Assert.assertTrue(testee.accept(currentFileInfo)); Assert.assertFalse(testee.accept(newFileInfo)); testee = new AgeFileFilter(NOW, false); Assert.assertFalse(testee.accept(oldFileInfo)); Assert.assertFalse(testee.accept(currentFileInfo)); Assert.assertTrue(testee.accept(newFileInfo)); // Same test with ZIP file FileObject[] files; files = zipFileObj.findFiles(new FileFilterSelector(new AgeFileFilter(NOW, true))); assertContains(files, oldFile.getName(), currentFile.getName()); Assert.assertEquals(2, files.length); files = zipFileObj.findFiles(new FileFilterSelector(new AgeFileFilter(NOW, false))); assertContains(files, newFile.getName()); Assert.assertEquals(1, files.length); }
Example #20
Source File: FileObjectRepository.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Returns the URL that represents this repository. The meaning of the URL returned here is implementation specific * and is probably not suitable to resolve names to global objects. * * @return the repository's URL. * @throws MalformedURLException if the URL could not be computed. */ public URL getURL() throws MalformedURLException { try { return root.getBackend().getURL(); } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
Example #21
Source File: SimpleVirtualFile.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean delete() throws VirtualFilesystemException { try { return this.file.delete(); } catch (FileSystemException e) { throw new VirtualFilesystemException(e); } }
Example #22
Source File: SimpleVirtualFile.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public void close() throws VirtualFilesystemException { try { this.file.close(); } catch (FileSystemException e) { throw new VirtualFilesystemException(e); } }
Example #23
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Returns an iterator over a set of all FileObject in this file object. * * @return an Iterator. */ @Override public Iterator<FileObject> iterator() { try { return listFiles(Selectors.SELECT_ALL).iterator(); } catch (final FileSystemException e) { throw new IllegalStateException(e); } }
Example #24
Source File: ResourceAgent.java From spoofax with Apache License 2.0 | 5 votes |
@Override public boolean exists(String fn) { try { final FileObject resource = resourceService.resolve(workingDir, fn); return resource.exists(); } catch(FileSystemException e) { throw new RuntimeException("Could not check if file " + fn + " exists", e); } }
Example #25
Source File: ResourceAgent.java From spoofax with Apache License 2.0 | 5 votes |
@Override public boolean writable(String fn) { try { final FileObject resource = resourceService.resolve(workingDir, fn); return resource.isWriteable(); } catch(FileSystemException e) { throw new RuntimeException("Could not check if file " + fn + " is writeable", e); } }
Example #26
Source File: Prd3139Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public void testSchemaResolve() throws FileSystemException { final URL url = Prd3139Test.class.getResource ( "/org/pentaho/reporting/engine/classic/extensions/datasources/mondrian/steelwheels.mondrian.xml" ); final String fileTxt = url.getFile(); final File file = new File( fileTxt ).getAbsoluteFile(); assertTrue( file.canRead() ); assertNotNull( SchemaResolver.resolveSchema( null, null, "../../../../../../../../../../../../../../" + file.getPath() ) ); }
Example #27
Source File: RepositoryExporter.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private String calcRepositoryDirectory( KettleFileRepository fileRep, FileObject fileObject ) throws FileSystemException { String path = fileObject.getParent().getName().getPath(); String baseDirectory = fileRep.getRepositoryMeta().getBaseDirectory(); // Double check! // if ( path.startsWith( baseDirectory ) ) { return path.substring( baseDirectory.length() ); } else { return path; } }
Example #28
Source File: ConnectionFileSystem.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public FileObject resolveFile( FileName name ) throws FileSystemException { try { return this.createFile( (AbstractFileName) name ); } catch ( Exception e ) { throw new FileSystemException( "vfs.provider/resolve-file.error", name, e ); } }
Example #29
Source File: Vfs444TestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
public void testResolvePartialPath2() throws FileSystemException { final FileName root = getManager().resolveURI("res:test-data"); final FileName file = getManager().resolveName(root, "test.zip"); final String uri = file.getURI(); final FileObject result = getManager().resolveFile(uri); Assert.assertNotNull(result); Assert.assertTrue(result.exists()); }
Example #30
Source File: VfsBrowser.java From otroslogviewer with Apache License 2.0 | 5 votes |
public void setSelectionMode(SelectionMode mode) { if (selectionMode == mode) { return; } SelectionMode oldValue = selectionMode; this.selectionMode = mode; firePropertyChange(MULTI_SELECTION_MODE_CHANGED_PROPERTY, oldValue, selectionMode); try { selectionChanged(); } catch (FileSystemException e) { LOGGER.error("Error during update state", e); } }