List of usage examples for org.apache.commons.vfs2 Selectors SELECT_ALL
FileSelector SELECT_ALL
To view the source code for org.apache.commons.vfs2 Selectors SELECT_ALL.
Click Source Link
From source file:binky.reportrunner.engine.utils.impl.FileSystemHandlerImpl.java
public void copyFile(String url, String destinationUrl) throws IOException { FileObject dest = fsManager.resolveFile(destinationUrl); FileObject src = fsManager.resolveFile(url); dest.copyFrom(src, Selectors.SELECT_ALL); }
From source file:de.innovationgate.utils.DirComparer.java
/** * Creates a comparer without filtering */ public DirComparer() { _fileSelector = Selectors.SELECT_ALL; }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does a 'cp' command./*from w w w . j a v a2 s . c om*/ * * @param cmd * @throws SimpleShellException */ public void cp(String[] cmd) throws SimpleShellException { if (cmd.length < 3) { throw new SimpleShellException("USAGE: cp <src> <dest>"); } FileObject src = null; try { src = mgr.resolveFile(cwd, cmd[1]); } catch (FileSystemException ex) { String errMsg = String.format("Error resolving source file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } FileObject dest = null; try { dest = mgr.resolveFile(cwd, cmd[2]); } catch (FileSystemException ex) { String errMsg = String.format("Error resolving destination file '%s'", cmd[2]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } } catch (FileSystemException ex) { String errMsg = String.format("Error resolving folder '%s'", cmd[2]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { dest.copyFrom(src, Selectors.SELECT_ALL); } catch (FileSystemException ex) { String errMsg = String.format("Error copyFrom() file '%s' to '%s'", cmd[1], cmd[2]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } }
From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java
public static void testVFS(String user, String pwd, String scheme, String host, String file) { StandardFileSystemManager fsManager = null; try {/*w w w . ja v a2 s .co m*/ fsManager = new StandardFileSystemManager(); fsManager.setLogger(_LOG); StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pwd); fsManager.setConfiguration(ConfigLoader.getInstance().get(Organizer.getVFSProviderConfig())); fsManager.setCacheStrategy(CacheStrategy.ON_RESOLVE); // fsManager.addProvider("moi", new DefaultLocalFileProvider()); fsManager.init(); FileSystemOptions opts = new FileSystemOptions(); FileSystemConfigBuilder fscb = fsManager.getFileSystemConfigBuilder(scheme); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); System.out.println(fsManager.getProviderCapabilities(scheme)); if (fscb instanceof FtpFileSystemConfigBuilder) { FtpFileSystemConfigBuilder ftpFscb = (FtpFileSystemConfigBuilder) fscb; ftpFscb.setUserDirIsRoot(opts, true); ftpFscb.setPassiveMode(opts, true); } if (fscb instanceof HttpFileSystemConfigBuilder) { HttpFileSystemConfigBuilder httpFscb = (HttpFileSystemConfigBuilder) fscb; httpFscb.setProxyHost(opts, "proxy.cls.fr"); httpFscb.setProxyPort(opts, 8080); } if (fscb instanceof SftpFileSystemConfigBuilder) { SftpFileSystemConfigBuilder sftpFscb = (SftpFileSystemConfigBuilder) fscb; sftpFscb.setUserDirIsRoot(opts, false); // TrustEveryoneUserInfo trustEveryoneUserInfo = new TrustEveryoneUserInfo(); // trustEveryoneUserInfo.promptYesNo("eddfsdfs"); // sftpFscb.setUserInfo(opts, new TrustEveryoneUserInfo()); sftpFscb.setTimeout(opts, 5000); // SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); // SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); } // FileObject fo = // fsManager.resolveFile("ftp://ftp.cls.fr/pub/oceano/AVISO/NRT-SLA/maps/rt/j2/h/msla_rt_j2_err_21564.nc.gz", // opts); // String uri = String.format("%s://%s/%s", scheme, host, file); // String uri = String.format("%s://%s/", scheme, host); // FileObject originBase = fsManager.resolveFile(uri, opts); // fsManager.setBaseFile(originBase); File tempDir = new File("c:/tempVFS"); // File tempFile = File.createTempFile("AsciiEnvisat", ".txt", tempDir); File hostFile = new File(file); String fileName = hostFile.getName(); File newFile = new File(tempDir, fileName); newFile.createNewFile(); DefaultFileReplicator dfr = new DefaultFileReplicator(tempDir); fsManager.setTemporaryFileStore(dfr); // System.out.println(fsManager.getBaseFile()); // System.out.println(dfr); // System.out.println(fsManager.getTemporaryFileStore()); // FileObject ff = fsManager.resolveFile("sftp://t:t@CLS-EARITH.pc.cls.fr/AsciiEnvisat.txt", // opts); String uri = String.format("%s://%s/%s", scheme, host, file); FileObject ff = fsManager.resolveFile(uri, opts); FileObject dest = fsManager.toFileObject(newFile); //ff.getContent().getInputStream(); dest.copyFrom(ff, Selectors.SELECT_ALL); //dest.copyFrom(ff, Selectors.SELECT_ALL); // // URL url = ff.getURL(); // // url.openConnection(); // URLConnection conn = url.openConnection(); // InputStream in = conn.getInputStream(); // in.close(); // InputStream in = ff.getContent().getInputStream(); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MotuException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // fsManager.close(); // fsManager.freeUnusedResources(); } }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Copy file.//from ww w. j a v a2 s . c o m * * @param user the user * @param pwd the pwd * @param scheme the scheme * @param host the host * @param fileSrc the file src * @param fileDest the file dest * * @throws MotuExceptionBase the motu exception base */ public void copyFileToLocalFile(String user, String pwd, String scheme, String host, String fileSrc, String fileDest) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("copyFileToLocalFile(String, String, String, String, String, String) - entering"); } open(user, pwd, scheme, null); FileObject foSrc = null; FileObject foDest = null; String uri = ""; try { File newFile = VFSManager.createLocalFile(fileDest); uri = String.format("%s://%s/%s", scheme, host, fileSrc); foSrc = resolveFile(uri); if (foSrc == null) { throw new MotuException(String.format("Unable to resolve source uri '%s' ", uri)); } foDest = standardFileSystemManager.toFileObject(newFile); if (foDest == null) { throw new MotuException(String.format("Unable to resolve dest uri '%s' ", fileDest)); } this.copyFrom(foSrc, foDest, Selectors.SELECT_ALL); } catch (MotuException e) { LOG.error("copyFileToLocalFile(String, String, String, String, String, String)", e); throw e; } catch (Exception e) { LOG.error("copyFileToLocalFile(String, String, String, String, String, String)", e); // throw new MotuException(String.format("Unable to copy file '%s' to '%s'", // foSrc.getURL().toString(), foDest.getURL().toString()), e); throw new MotuException(String.format("Unable to copy file '%s' to '%s'", uri.toString(), fileDest), e); } if (LOG.isDebugEnabled()) { LOG.debug("copyFileToLocalFile(String, String, String, String, String, String) - exiting"); } }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Copy file to local file./*from w ww .ja va2 s. c om*/ * * @param uriSrc the uri src * @param fileDest the file dest * * @throws MotuException the motu exception */ public void copyFileToLocalFile(String uriSrc, String fileDest) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("copyFileToLocalFile(String, String) - entering"); } // URI uri = new URI(uriSrc); // // String[] userInfo = uri.getUserInfo().split(":"); // String user = ""; // String pwd = ""; // // if (userInfo.length >= 2) { // pwd = userInfo[1]; // } // // if (userInfo.length >= 1) { // user = userInfo[0]; // } // // copyFile(user, pwd, uri.getScheme(), uri. FileObject foSrc = null; FileObject foDest = null; try { File newFile = VFSManager.createLocalFile(fileDest); foSrc = resolveFile(uriSrc); if (foSrc == null) { throw new MotuException(String.format("Unable to resolve source uri '%s' ", uriSrc)); } foDest = standardFileSystemManager.toFileObject(newFile); if (foDest == null) { throw new MotuException( String.format("Unable to resolve dest uri '%s' ", newFile.getAbsolutePath())); } this.copyFrom(foSrc, foDest, Selectors.SELECT_ALL); } catch (MotuException e) { LOG.error("copyFileToLocalFile(String, String)", e); throw e; } catch (Exception e) { LOG.error("copyFileToLocalFile(String, String)", e); try { throw new MotuException(String.format("Unable to copy file '%s' to '%s'", foSrc.getURL().toString(), foDest.getURL().toString()), e); } catch (FileSystemException e1) { LOG.error("copyFileToLocalFile(String, String)", e1); throw new MotuException(String.format("Unable to copy files", e1)); } } if (LOG.isDebugEnabled()) { LOG.debug("copyFileToLocalFile(String, String) - exiting"); } }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Delete directory nd all descendents of the file. * //from w w w. jav a 2 s . c o m * @param file the file * * @return true, if successful * @throws MotuException */ public boolean deleteDirectory(FileObject file) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("deleteDirectory(FileObject) - entering"); } boolean returnboolean = delete(file, Selectors.SELECT_ALL); if (LOG.isDebugEnabled()) { LOG.debug("deleteDirectory(FileObject) - exiting"); } return returnboolean; }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Copy file./*from w w w . j av a 2s .co m*/ * * @param from the from * @param to the to * * @throws MotuException the motu exception */ public void copyFile(FileObject from, FileObject to) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("copyFile(FileObject, FileObject) - entering"); } try { if ((to.exists()) && (to.getType() == FileType.FOLDER)) { throw new MotuException(String.format( "File copy from '%s' to '%s' is rejected: the destination already exists and is a folder. You were about to loose all of the content of '%s' ", from.getName().toString(), to.getName().toString(), to.getName().toString())); } this.copyFrom(from, to, Selectors.SELECT_ALL); } catch (MotuException e) { LOG.error("copyFile(FileObject, FileObject)", e); throw e; } catch (Exception e) { LOG.error("copyFile(FileObject, FileObject)", e); // throw new MotuException(String.format("Unable to copy file '%s' to '%s'", // foSrc.getURL().toString(), foDest.getURL().toString()), e); throw new MotuException(String.format("Unable to copy file '%s' to '%s'", from.getName().toString(), to.getName().toString()), e); } if (LOG.isDebugEnabled()) { LOG.debug("copyFile(FileObject, FileObject) - exiting"); } }
From source file:com.sonicle.webtop.vfs.VfsManager.java
private void doDeleteStoreFile(int storeId, String path) throws FileSystemException, SQLException, DAOException, WTException { SharingLinkDAO dao = SharingLinkDAO.getInstance(); FileObject tfo = null;/* www.j av a 2s .c om*/ Connection con = null; try { tfo = getTargetFileObject(storeId, path); logger.debug("Deleting store file [{}, {}]", storeId, path); try { con = WT.getConnection(SERVICE_ID, false); dao.deleteByStorePath(con, storeId, path); tfo.delete(Selectors.SELECT_ALL); DbUtils.commitQuietly(con); } catch (FileSystemException ex1) { DbUtils.rollbackQuietly(con); throw ex1; } finally { DbUtils.closeQuietly(con); } } finally { IOUtils.closeQuietly(tfo); } }
From source file:org.apache.commons.vfs2.example.Shell.java
/** * Does a 'cp' command.// w w w . java 2 s . com */ private void cp(final String[] cmd) throws Exception { if (cmd.length < 3) { throw new Exception("USAGE: cp <src> <dest>"); } final FileObject src = mgr.resolveFile(cwd, cmd[1]); FileObject dest = mgr.resolveFile(cwd, cmd[2]); if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } dest.copyFrom(src, Selectors.SELECT_ALL); }