List of usage examples for org.apache.commons.vfs2 FileSystemOptions FileSystemOptions
public FileSystemOptions()
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A003_exist() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net String currFileNameStr;// w w w .ja va 2s . com DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); Boolean existRes = currFile.exists(); Assert.assertTrue(existRes); currFileNameStr = "non-existant-file-8632857264.tmp"; currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currAccountStr, currContainerStr, currFileNameStr); currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); existRes = currFile.exists(); Assert.assertFalse(existRes); }
From source file:hadoopInstaller.installation.Installer.java
private void configureVFS2SFTP() throws InstallationFatalError { getLog().trace("HadoopInstaller.Configure.SFTP.Start"); //$NON-NLS-1$ FileSystemOptions options;/* w ww .j a va 2 s. c om*/ options = new FileSystemOptions(); SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); try { builder.setUserDirIsRoot(options, false); /* * TODO-- ssh-ask * * In the case of ask, the UserInfo object should be passed with * builder.setUserInfo() */ builder.setStrictHostKeyChecking(options, this.configuration.getStrictHostKeyChecking() ? "yes" : "no"); //$NON-NLS-1$//$NON-NLS-2$ getLog().trace("HadoopInstaller.Configure.StrictHostKeyChecking", //$NON-NLS-1$ this.configuration.getStrictHostKeyChecking()); builder.setKnownHosts(options, new File(this.configuration.getSshKnownHosts())); getLog().trace("HadoopInstaller.Configure.KnownHosts", //$NON-NLS-1$ this.configuration.getSshKnownHosts()); File identities[] = { new File(getConfig().getSshKeyFile()) }; getLog().trace("HadoopInstaller.Configure.PrivateKeyFile", //$NON-NLS-1$ getConfig().getSshKeyFile()); builder.setIdentities(options, identities); /* * TODO-- ssh-ask * * what if the identities file is password protected? do we need to * use setUserInfo? */ } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.Configure.SFTP.Fail"); //$NON-NLS-1$ } this.sftpOptions = options; getLog().debug("HadoopInstaller.Configure.SFTP.Success"); //$NON-NLS-1$ }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A003_exist() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;/* w ww .j ava 2s.c o m*/ SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); Boolean existRes = currFile.exists(); Assert.assertTrue(existRes); currFileNameStr = "non-existant-file-8632857264.tmp"; currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); existRes = currFile.exists(); Assert.assertFalse(existRes); }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Open.//w w w .j ava2 s . c o m * * @param user the user * @param pwd the pwd * @param scheme the scheme * * @throws MotuException the motu exception */ public void open(String user, String pwd, String scheme, String host) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("open(String, String, String) - entering"); } if (isOpened()) { if (LOG.isDebugEnabled()) { LOG.debug("open(String, String, String) - exiting"); } return; } standardFileSystemManager = new StandardFileSystemManager(); standardFileSystemManager.setLogger(LogFactory.getLog(VFS.class)); standardFileSystemManager.setClassLoader(this.getClass().getClassLoader()); try { standardFileSystemManager .setConfiguration(ConfigLoader.getInstance().get(Organizer.getVFSProviderConfig())); //standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL); standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_RESOLVE); // standardFileSystemManager.setFilesCache(new SoftRefFilesCache()); // standardFileSystemManager.addProvider("jar", new JarFileProvider()); standardFileSystemManager.init(); open = true; } catch (FileSystemException e) { LOG.fatal("Error in VFS initialisation - Unable to intiialize VFS", e); throw new MotuException("Error in VFS initialisation - Unable to intiialize VFS", e); } catch (IOException e) { LOG.fatal("Error in VFS initialisation - Unable to intiialize VFS", e); throw new MotuException("Error in VFS initialisation - Unable to intiialize VFS", e); } opts = new FileSystemOptions(); setUserInfo(user, pwd); setSchemeOpts(scheme, host); if (LOG.isDebugEnabled()) { LOG.debug("open(String, String, String) - exiting"); } }
From source file:com.github.abola.crawler.CrawlerPack.java
/** * ?? Apache Common VFS ???//w ww .jav a 2 s . co m * * ?? * @see <a href="https://commons.apache.org/proper/commons-vfs/filesystems.html">commons-vfs filesystems</a> */ public String getFromRemote(String uri) { // clear cache fileSystem.getFilesCache().close(); String remoteContent; String remoteEncoding = "utf-8"; log.debug("getFromRemote: Loading remote URI=" + uri); FileContent fileContent; try { FileSystemOptions fsOptions = new FileSystemOptions(); // set userAgent HttpFileSystemConfigBuilder.getInstance().setUserAgent(fsOptions, userAgent); // set cookie if cookies set if (0 < this.cookies.size()) { HttpFileSystemConfigBuilder.getInstance().setCookies(fsOptions, getCookies(uri)); } log.debug("getFromRemote: userAgent=" + userAgent); log.debug("getFromRemote: cookieSize=" + cookies.size()); log.debug("getFromRemote: cookies=" + cookies.toString()); fileContent = fileSystem.resolveFile(uri, fsOptions).getContent(); // 2016-03-22 only pure http/https auto detect encoding if ("http".equalsIgnoreCase(uri.substring(0, 4))) { fileContent.getSize(); // pass a bug {@link https://issues.apache.org/jira/browse/VFS-427} remoteEncoding = fileContent.getContentInfo().getContentEncoding(); } log.debug("getFromRemote: remoteEncoding=" + remoteEncoding + "(auto detect) "); // 2016-03-21 zip file getContentEncoding null if (null == remoteEncoding) remoteEncoding = "utf-8"; if (!"utf".equalsIgnoreCase(remoteEncoding.substring(0, 3))) { log.debug("getFromRemote: remote content encoding=" + remoteEncoding); // force charset encoding if setRemoteEncoding set if (!"utf".equalsIgnoreCase(encoding.substring(0, 3))) { remoteEncoding = encoding; } else { // auto detecting encoding remoteEncoding = detectCharset(IOUtils.toByteArray(fileContent.getInputStream())); log.debug("getFromRemote: real encoding=" + remoteEncoding); } } // ?? Apache VFS ?? // 2016-02-29 fixed remoteContent = IOUtils.toString(fileContent.getInputStream(), remoteEncoding); } catch (FileSystemException fse) { log.warn("getFromRemote: FileSystemException=" + fse.getMessage()); remoteContent = null; } catch (IOException ioe) { // return empty log.warn("getFromRemote: IOException=" + ioe.getMessage()); remoteContent = null; } catch (StringIndexOutOfBoundsException stre) { log.warn("getFromRemote: StringIndexOutOfBoundsException=" + stre.getMessage()); log.warn("getFromRemote: uri=" + uri); log.warn(stre.getMessage()); remoteContent = null; } clearCookies(); log.debug("getFromRemote: remoteContent=\n" + remoteContent); // any exception will return "null" return remoteContent; }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A004_getContentSize() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net String currFileNameStr;/* w ww . j av a 2 s .co m*/ DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); FileContent cont = currFile.getContent(); long contSize = cont.getSize(); Assert.assertTrue(contSize > 0); }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Sets the user info.//from w w w.j a v a 2s . c om * * @param user the user * @param pwd the pwd * @param fileSystemOptions the file system options * @return the file system options * @throws MotuException the motu exception */ public FileSystemOptions setUserInfo(String user, String pwd, FileSystemOptions fileSystemOptions) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("setUserInfo(String, String, FileSystemOptions) - start"); } if (fileSystemOptions == null) { fileSystemOptions = new FileSystemOptions(); } StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pwd); FileSystemOptions returnFileSystemOptions = setUserInfo(auth); if (LOG.isDebugEnabled()) { LOG.debug("setUserInfo(String, String, FileSystemOptions) - end"); } return returnFileSystemOptions; }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A004_getContentSize() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;/* www . ja va2s . co m*/ SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("getContent() file '%s'", currUriStr)); FileContent cont = currFile.getContent(); long contSize = cont.getSize(); Assert.assertTrue(contSize > 0); }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
/** * By default FileObject.getChildren() will use doListChildrenResolved() if available * /* www. j a v a2s . c om*/ * @throws Exception */ @Test public void A005_listChildren() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currFileNameStr = "uploadFile02"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject[] currObjs = currFile.getChildren(); for (FileObject obj : currObjs) { FileName currName = obj.getName(); Boolean res = obj.exists(); FileType ft = obj.getType(); log.info(String.format("\nNAME.PATH : '%s'\nEXISTS : %b\nTYPE : %s\n\n", currName.getPath(), res, ft)); } }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Sets the user info./*from ww w .j a v a2 s .c o m*/ * * @param auth the auth * * @return the file system options * * @throws MotuException the motu exception */ public FileSystemOptions setUserInfo(UserAuthenticator auth) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("setUserInfo(StaticUserAuthenticator) - entering"); } if (opts == null) { opts = new FileSystemOptions(); } if (auth == null) { if (LOG.isDebugEnabled()) { LOG.debug("setUserInfo(StaticUserAuthenticator) - exiting"); } return opts; } try { DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); } catch (FileSystemException e) { LOG.error("setUserInfo(StaticUserAuthenticator)", e); throw new MotuException("Error in VFSManager#setUserInfo", e); } if (LOG.isDebugEnabled()) { LOG.debug("setUserInfo(StaticUserAuthenticator) - exiting"); } return opts; }