List of usage examples for org.apache.commons.vfs2 FileSystemException FileSystemException
public FileSystemException(final String code, final Throwable throwable)
From source file:com.github.junrar.vfs2.provider.rar.RARFileObject.java
@Override protected InputStream doGetInputStream() throws Exception { if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); }/*from www . j av a 2 s .co m*/ return archive.getInputStream(header); }
From source file:com.github.songsheng.vfs2.provider.nfs.NfsFileObject.java
/** * Determines the type of the file, returns null if the file does not * exist./*from w w w . j ava 2 s. co m*/ */ @Override protected FileType doGetType() throws Exception { if (!file.exists()) { return FileType.IMAGINARY; } else if (file.isDirectory()) { return FileType.FOLDER; } else if (file.isFile()) { return FileType.FILE; } throw new FileSystemException("vfs.provider.Nfs/get-type.error", getName()); }
From source file:maspack.fileutil.FileCacher.java
public File cache(URIx uri, File cacheFile, FileTransferMonitor monitor) throws FileSystemException { // For atomic operation, first download to temporary directory File tmpCacheFile = new File(cacheFile.getAbsolutePath() + TMP_EXTENSION); URIx cacheURI = new URIx(cacheFile.getAbsoluteFile()); URIx tmpCacheURI = new URIx(tmpCacheFile.getAbsoluteFile()); FileObject localTempFile = manager.resolveFile(tmpCacheURI.toString(true)); FileObject localCacheFile = manager.resolveFile(cacheURI.toString(true)); FileObject remoteFile = null; // will resolve next // loop through authenticators until we either succeed or cancel boolean cancel = false; while (remoteFile == null && cancel == false) { remoteFile = resolveRemote(uri); }//ww w.jav a 2 s . c om if (remoteFile == null || !remoteFile.exists()) { throw new FileSystemException("Cannot find remote file <" + uri.toString() + ">", new FileNotFoundException("<" + uri.toString() + ">")); } // monitor the file transfer progress if (monitor != null) { monitor.monitor(localTempFile, remoteFile, -1, cacheFile.getName()); monitor.start(); monitor.fireStartEvent(localTempFile); } // transfer content try { if (remoteFile.isFile()) { localTempFile.copyFrom(remoteFile, Selectors.SELECT_SELF); } else if (remoteFile.isFolder()) { // final FileObject fileSystem = manager.createFileSystem(remoteFile); localTempFile.copyFrom(remoteFile, new AllFileSelector()); // fileSystem.close(); } if (monitor != null) { monitor.fireCompleteEvent(localTempFile); } } catch (Exception e) { // try to delete local file localTempFile.delete(); throw new RuntimeException( "Failed to complete transfer of " + remoteFile.getURL() + " to " + localTempFile.getURL(), e); } finally { // close files if we need to localTempFile.close(); remoteFile.close(); if (monitor != null) { monitor.release(localTempFile); monitor.stop(); } } // now that the copy is complete, do a rename operation try { if (tmpCacheFile.isDirectory()) { SafeFileUtils.moveDirectory(tmpCacheFile, cacheFile); } else { SafeFileUtils.moveFile(tmpCacheFile, cacheFile); } } catch (Exception e) { localCacheFile.delete(); // delete if possible throw new RuntimeException("Failed to atomically move " + "to " + localCacheFile.getURL(), e); } return cacheFile; }
From source file:io.hops.hopsworks.api.zeppelin.util.ZeppelinResource.java
private FileObject[] getPidFiles(Project project) throws URISyntaxException, FileSystemException { ZeppelinConfig zepConf = zeppelinConfFactory.getProjectConf(project.getName()); if (zepConf == null) { return new FileObject[0]; }//from w ww . j a va 2s . com ZeppelinConfiguration conf = zepConf.getConf(); URI filesystemRoot; FileSystemManager fsManager; String runPath = conf.getRelativeDir("run"); try { filesystemRoot = new URI(runPath); } catch (URISyntaxException e1) { throw new URISyntaxException("Not a valid URI", e1.getMessage()); } if (filesystemRoot.getScheme() == null) { // it is local path try { filesystemRoot = new URI(new File(runPath).getAbsolutePath()); } catch (URISyntaxException e) { throw new URISyntaxException("Not a valid URI", e.getMessage()); } } FileObject[] pidFiles = null; try { fsManager = VFS.getManager(); // pidFiles = fsManager.resolveFile(filesystemRoot.toString() + "/"). pidFiles = fsManager.resolveFile(filesystemRoot.getPath()).getChildren(); } catch (FileSystemException ex) { throw new FileSystemException("Directory not found: " + filesystemRoot.getPath(), ex.getMessage()); } return pidFiles; }
From source file:com.seeburger.vfs2.util.VFSClassLoader.java
/** * Loads and verifies the class with name and located with res. *///from www . jav a 2 s . c om private Class<?> defineClass(final String name, final Resource res) throws IOException { final URL url = res.getCodeSourceURL(); final String pkgName = res.getPackageName(); if (pkgName != null) { final Package pkg = getPackage(pkgName); if (pkg != null) { if (pkg.isSealed()) { if (!pkg.isSealed(url)) { throw new FileSystemException("vfs.impl/pkg-sealed-other-url", pkgName); } } else { if (isSealed(res)) { throw new FileSystemException("vfs.impl/pkg-sealing-unsealed", pkgName); } } } else { definePackage(pkgName, res); } } final byte[] bytes = res.getBytes(); final Certificate[] certs = res.getFileObject().getContent().getCertificates(); final CodeSource cs = new CodeSource(url, certs); return defineClass(name, bytes, 0, bytes.length, cs); }
From source file:maspack.fileutil.FileCacher.java
public boolean copy(URIx from, URIx to, FileTransferMonitor monitor) throws FileSystemException { FileObject fromFile = null;/*from w w w. j a va 2 s . c o m*/ FileObject toFile = null; // clear authenticators setAuthenticator(fsOpts, null); setIdentityFactory(fsOpts, null); // loop through authenticators until we either succeed or cancel boolean cancel = false; while (toFile == null && cancel == false) { toFile = resolveRemote(to); } cancel = false; while (fromFile == null && cancel == false) { fromFile = resolveRemote(from); } if (fromFile == null || !fromFile.exists()) { throw new FileSystemException("Cannot find source file <" + from.toString() + ">", new FileNotFoundException("<" + from.toString() + ">")); } if (toFile == null) { throw new FileSystemException("Cannot find destination <" + to.toString() + ">", new FileNotFoundException("<" + to.toString() + ">")); } // monitor the file transfer progress if (monitor != null) { monitor.monitor(fromFile, toFile, -1, fromFile.getName().getBaseName()); monitor.start(); monitor.fireStartEvent(toFile); } // transfer content try { if (fromFile.isFile()) { toFile.copyFrom(fromFile, Selectors.SELECT_SELF); } else if (fromFile.isFolder()) { // final FileObject fileSystem = manager.createFileSystem(remoteFile); toFile.copyFrom(fromFile, new AllFileSelector()); // fileSystem.close(); } if (monitor != null) { monitor.fireCompleteEvent(toFile); } } catch (Exception e) { throw new FileTransferException( "Failed to complete transfer of " + fromFile.getURL() + " to " + toFile.getURL(), e); } finally { // close files if we need to fromFile.close(); toFile.close(); if (monitor != null) { monitor.release(toFile); monitor.stop(); } } return true; }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java
/** * Determines the type of the file, returns null if the file does not exist. * /*from w w w. j av a 2 s. co m*/ * @return the file type * * @throws Exception the exception */ @Override protected FileType doGetType() throws Exception { // log.debug("relative path:" + relPath); if (this.fileInfo == null) { return FileType.IMAGINARY; } else if (this.fileInfo.isDirectory()) { return FileType.FOLDER; } else if (this.fileInfo.isFile()) { return FileType.FILE; } else if (this.fileInfo.isSoftLink()) { return FileType.FILE; // getLinkDestination().getType(); } throw new FileSystemException("vfs.provider.gsiftp/get-type.error", getName()); }
From source file:maspack.fileutil.FileCacher.java
public InputStream getInputStream(URIx uri) throws FileSystemException { FileObject remoteFile = null; // will resolve next // loop through authenticators until we either succeed or cancel boolean cancel = false; while (remoteFile == null && cancel == false) { remoteFile = resolveRemote(uri); }/*from w w w .ja va 2 s . c o m*/ if (remoteFile == null || !remoteFile.exists()) { throw new FileSystemException("Cannot find remote file <" + uri.toString() + ">", new FileNotFoundException("<" + uri.toString() + ">")); } // open stream content InputStream stream = null; try { stream = remoteFile.getContent().getInputStream(); } catch (Exception e) { remoteFile.close(); throw new RuntimeException("Failed to open " + remoteFile.getURL(), e); } finally { } return stream; }
From source file:maspack.fileutil.FileCacher.java
public OutputStream getOutputStream(URIx uri) throws FileSystemException { FileObject remoteFile = null; // will resolve next // loop through authenticators until we either succeed or cancel boolean cancel = false; while (remoteFile == null && cancel == false) { remoteFile = resolveRemote(uri); }//from w w w .j a v a 2 s . co m if (remoteFile == null) { throw new FileSystemException("Cannot find remote file <" + uri.toString() + ">", new FileNotFoundException("<" + uri.toString() + ">")); } // open stream content OutputStream stream = null; try { stream = remoteFile.getContent().getOutputStream(); } catch (Exception e) { throw new RuntimeException("Failed to open " + remoteFile.getURL(), e); } finally { remoteFile.close(); } return stream; }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java
/** * Deletes the file.//from www . ja va2s . co m * * @throws Exception the exception */ @Override protected void doDelete() throws Exception { boolean ok = true; final GridFTPClient ftpClient = ftpFs.getClient(); try { // String Path = relPath; // if ( ! relPath.startsWith("/")) { // Path = "/" + Path; // log.warn("relative path " + relPath + " doesn't start with (/). Using:" + Path + " instead"); // } if (this.fileInfo.isDirectory()) { ftpClient.deleteDir(getName().getPath()); } else { ftpClient.deleteFile(getName().getPath()); } } catch (IOException ioe) { ok = false; } catch (ServerException e) { ok = false; } finally { ftpFs.putClient(ftpClient); } if (!ok) { throw new FileSystemException("vfs.provider.gsiftp/delete-file.error", getName()); } this.fileInfo = null; children = EMPTY_FTP_FILE_MAP; }