List of usage examples for org.apache.commons.vfs2 FileSystemOptions FileSystemOptions
public FileSystemOptions()
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A005_testContent() 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;//from w w w .j ava 2 s. 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 = "file05"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileContent content = currFile.getContent(); long size = content.getSize(); Assert.assertTrue(size >= 0); long modTime = content.getLastModifiedTime(); Assert.assertTrue(modTime > 0); }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Sets the scheme./*from w ww. j a va 2 s .c o m*/ * * @param scheme the scheme * * @return the file system options * * @throws MotuException the motu exception */ public FileSystemOptions setSchemeOpts(String scheme, String host) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("setSchemeOpts(String, String) - start"); } if (Organizer.isNullOrEmpty(scheme)) { if (LOG.isDebugEnabled()) { LOG.debug("setSchemeOpts(String, String) - end"); } return opts; } if (opts == null) { opts = new FileSystemOptions(); } FileSystemConfigBuilder fscb = null; MotuConfigFileSystemWrapper<Boolean> wrapperBoolean = new MotuConfigFileSystemWrapper<Boolean>(); MotuConfigFileSystemWrapper<Period> wrapperPeriod = new MotuConfigFileSystemWrapper<Period>(); MotuConfigFileSystemWrapper<String> wrapperString = new MotuConfigFileSystemWrapper<String>(); try { try { fscb = standardFileSystemManager.getFileSystemConfigBuilder(scheme); } catch (FileSystemException e) { LOG.error("setSchemeOpts(String)", e); fscb = standardFileSystemManager.getFileSystemConfigBuilder(VFSManager.DEFAULT_SCHEME); } if (fscb instanceof FtpFileSystemConfigBuilder) { FtpFileSystemConfigBuilder ftpFscb = (FtpFileSystemConfigBuilder) fscb; Boolean userDirIsRoot = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_FTPUSERDIRISROOT); if (userDirIsRoot != null) { ftpFscb.setUserDirIsRoot(opts, userDirIsRoot); } else { ftpFscb.setUserDirIsRoot(opts, false); } Boolean passiveMode = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_FTPPASSIVEMODE); ; if (passiveMode != null) { ftpFscb.setPassiveMode(opts, passiveMode); } Period dataTimeOut = wrapperPeriod.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_FTPDATATIMEOUT); if (dataTimeOut != null) { long value = dataTimeOut.toStandardDuration().getMillis(); if (value > Integer.MAX_VALUE) { throw new MotuException(String.format( "Motu Configuration : sftp timeout value is too large '%ld' milliseconds. Max is '%d'", value, Integer.MAX_VALUE)); } if (value > 0) { ftpFscb.setDataTimeout(opts, (int) value); } } } if (fscb instanceof HttpFileSystemConfigBuilder) { HttpFileSystemConfigBuilder httpFscb = (HttpFileSystemConfigBuilder) fscb; Boolean isUseProxy = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_USEHTTPPROXY); if ((isUseProxy != null) && (isUseProxy)) { String proxyHost = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_HTTPPROXYHOST); String proxyPort = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_HTTPPROXYPORT); httpFscb.setProxyHost(opts, proxyHost); httpFscb.setProxyPort(opts, Integer.parseInt(proxyPort)); } } if (fscb instanceof SftpFileSystemConfigBuilder) { SftpFileSystemConfigBuilder sftpFscb = (SftpFileSystemConfigBuilder) fscb; Boolean userDirIsRoot = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPUSERDIRISROOT); if (userDirIsRoot != null) { sftpFscb.setUserDirIsRoot(opts, userDirIsRoot); } else { sftpFscb.setUserDirIsRoot(opts, false); } String strictHostKeyChecking = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_STRICTHOSTKEYCHECKING); if (strictHostKeyChecking != null) { sftpFscb.setStrictHostKeyChecking(opts, strictHostKeyChecking); } Period SftpSessionTimeOut = wrapperPeriod.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPSESSIONTIMEOUT); if (SftpSessionTimeOut != null) { long value = SftpSessionTimeOut.toStandardDuration().getMillis(); if (value > Integer.MAX_VALUE) { throw new MotuException(String.format( "Motu Configuration : sftp timeout value is too large '%ld' milliseconds. Max is '%d'", value, Integer.MAX_VALUE)); } if (value > 0) { sftpFscb.setTimeout(opts, (int) value); } } Boolean isUseProxy = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_USESFTPPROXY); if ((isUseProxy != null) && (isUseProxy)) { String proxyHost = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPPROXYHOST); String proxyPort = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPPROXYPORT); sftpFscb.setProxyHost(opts, proxyHost); sftpFscb.setProxyPort(opts, Integer.parseInt(proxyPort)); } } } catch (FileSystemException e) { LOG.error("setSchemeOpts(String, String)", e); throw new MotuException("Error in VFSManager#setScheme", e); } if (LOG.isDebugEnabled()) { LOG.debug("setSchemeOpts(String, String) - end"); } return opts; }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A006_testContent() 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;/*from w w w .j a v a 2s. c o 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 = "file05"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileContent content = currFile.getContent(); long size = content.getSize(); Assert.assertTrue(size >= 0); long modTime = content.getLastModifiedTime(); Assert.assertTrue(modTime > 0); }
From source file:com.app.server.JarDeployer.java
/** * This method implements the jar deployer which configures the executor services. * Frequently monitors the deploy directory and configures the executor services map * once the jar is deployed in deploy directory and reconfigures if the jar is modified and * placed in the deploy directory.//from www . j a va 2 s. com */ public void run() { StandardFileSystemManager fsManager = new StandardFileSystemManager(); try { fsManager.init(); DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator); } catch (FileSystemException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } File file = new File(scanDirectory.split(";")[0]); File[] files = file.listFiles(); CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().endsWith(".jar")) { String filePath = files[i].getAbsolutePath(); FileObject jarFile = null; try { jarFile = fsManager.resolveFile("jar:" + filePath); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".jar")); WebClassLoader customClassLoader = null; try { URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); try { customClassLoader = new WebClassLoader(urls); log.info(customClassLoader.geturlS()); customClassLoader.addURL(new URL("file:/" + files[i].getAbsolutePath())); CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList(); getUsersJars(new File(libDir), jarList); for (String jarFilePath : jarList) customClassLoader.addURL(new URL("file:/" + jarFilePath.replace("\\", "/"))); log.info("deploy=" + customClassLoader.geturlS()); this.urlClassLoaderMap.put(scanDirectory + "/" + files[i].getName(), customClassLoader); jarsDeployed.add(files[i].getName()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } log.info(urlClassLoaderMap); getChildren(jarFile, classList); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (int classCount = 0; classCount < classList.size(); classCount++) { String classwithpackage = classList.get(classCount).substring(0, classList.get(classCount).indexOf(".class")); classwithpackage = classwithpackage.replace("/", "."); log.info("classList:" + classwithpackage.replace("/", ".")); try { if (!classwithpackage.contains("$")) { Class executorServiceClass = customClassLoader.loadClass(classwithpackage); //log.info("executor class in ExecutorServicesConstruct"+executorServiceClass); //log.info(); if (!executorServiceClass.isInterface()) { Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations(); if (classServicesAnnot != null) { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof RemoteCall) { RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount]; //registry.unbind(remoteCall.servicename()); log.info(remoteCall.servicename().trim()); try { //for(int count=0;count<500;count++){ RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject .exportObject((Remote) executorServiceClass.newInstance(), 2004); registry.rebind(remoteCall.servicename().trim(), reminterface); //} } catch (Exception ex) { ex.printStackTrace(); } } } } } Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation; ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo(); executorServiceInfo.setExecutorServicesClass(executorServiceClass); executorServiceInfo.setMethod(method); executorServiceInfo.setMethodParams(method.getParameterTypes()); //log.info("method="+executorServiceAnnot.servicename()); //log.info("method info="+executorServiceInfo); //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception(); executorServiceMap.put(executorServiceAnnot.servicename(), executorServiceInfo); } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } ClassLoaderUtil.closeClassLoader(customClassLoader); try { jarFile.close(); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } fsManager.closeFileSystem(jarFile.getFileSystem()); } } fsManager.close(); fsManager = new StandardFileSystemManager(); try { DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JarFileListener jarFileListener = new JarFileListener(executorServiceMap, libDir, urlClassLoaderMap, jarsDeployed); DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener); jarFileListener.setFm(fm); FileObject listendir = null; String[] dirsToScan = scanDirectory.split(";"); try { FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); fsManager.init(); for (String dir : dirsToScan) { if (dir.startsWith("ftp://")) { listendir = fsManager.resolveFile(dir, opts); } else { listendir = fsManager.resolveFile(dir); } fm.addFile(listendir); } } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } fm.setRecursive(true); fm.setDelay(3000); fm.start(); //fsManager.close(); }
From source file:com.web.server.JarDeployer.java
/** * This method implements the jar deployer which configures the executor services. * Frequently monitors the deploy directory and configures the executor services map * once the jar is deployed in deploy directory and reconfigures if the jar is modified and * placed in the deploy directory./*from w w w . j a v a 2 s .c om*/ */ public void run() { StandardFileSystemManager fsManager = new StandardFileSystemManager(); try { fsManager.init(); DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator); } catch (FileSystemException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } File file = new File(scanDirectory.split(";")[0]); File[] files = file.listFiles(); CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().endsWith(".jar")) { String filePath = files[i].getAbsolutePath(); FileObject jarFile = null; try { jarFile = fsManager.resolveFile("jar:" + filePath); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".jar")); WebClassLoader customClassLoader = null; try { URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); try { customClassLoader = new WebClassLoader(urls); System.out.println(customClassLoader.geturlS()); new WebServer().addURL(new URL("file:/" + files[i].getAbsolutePath()), customClassLoader); CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList(); getUsersJars(new File(libDir), jarList); for (String jarFilePath : jarList) new WebServer().addURL(new URL("file:/" + jarFilePath.replace("\\", "/")), customClassLoader); System.out.println("deploy=" + customClassLoader.geturlS()); this.urlClassLoaderMap.put(scanDirectory + "/" + files[i].getName(), customClassLoader); jarsDeployed.add(files[i].getName()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(urlClassLoaderMap); getChildren(jarFile, classList); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (int classCount = 0; classCount < classList.size(); classCount++) { String classwithpackage = classList.get(classCount).substring(0, classList.get(classCount).indexOf(".class")); classwithpackage = classwithpackage.replace("/", "."); System.out.println("classList:" + classwithpackage.replace("/", ".")); try { if (!classwithpackage.contains("$")) { Class executorServiceClass = customClassLoader.loadClass(classwithpackage); //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); //System.out.println(); if (!executorServiceClass.isInterface()) { Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations(); if (classServicesAnnot != null) { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof RemoteCall) { RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount]; //registry.unbind(remoteCall.servicename()); System.out.println(remoteCall.servicename().trim()); try { //for(int count=0;count<500;count++){ RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject .exportObject((Remote) executorServiceClass.newInstance(), 2004); registry.rebind(remoteCall.servicename().trim(), reminterface); //} } catch (Exception ex) { ex.printStackTrace(); } } } } } Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation; ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo(); executorServiceInfo.setExecutorServicesClass(executorServiceClass); executorServiceInfo.setMethod(method); executorServiceInfo.setMethodParams(method.getParameterTypes()); //System.out.println("method="+executorServiceAnnot.servicename()); //System.out.println("method info="+executorServiceInfo); //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception(); executorServiceMap.put(executorServiceAnnot.servicename(), executorServiceInfo); } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } ClassLoaderUtil.closeClassLoader(customClassLoader); try { jarFile.close(); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } fsManager.closeFileSystem(jarFile.getFileSystem()); } } fsManager.close(); fsManager = new StandardFileSystemManager(); try { DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JarFileListener jarFileListener = new JarFileListener(executorServiceMap, libDir, urlClassLoaderMap, jarsDeployed); DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener); jarFileListener.setFm(fm); FileObject listendir = null; String[] dirsToScan = scanDirectory.split(";"); try { FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); fsManager.init(); for (String dir : dirsToScan) { if (dir.startsWith("ftp://")) { listendir = fsManager.resolveFile(dir, opts); } else { listendir = fsManager.resolveFile(dir); } fm.addFile(listendir); } } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } fm.setRecursive(true); fm.setDelay(3000); fm.start(); //fsManager.close(); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * Delete a previously uploaded file.//from w w w. java 2 s . c o m * * @throws Exception */ @Test public void A006_deleteFile() 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; 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("deleting '%s'", currUriStr)); Boolean delRes = currFile.delete(); Assert.assertTrue(delRes); }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A007_deleteFile() 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 .j ava 2 s . 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("deleting '%s'", currUriStr)); Boolean delRes = currFile.delete(); Assert.assertTrue(delRes); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * By default FileObject.getChildren() will use doListChildrenResolved() if available * //from w w w. j a va2 s .co m * @throws Exception */ @Test public void A007_listChildren() 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"); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); SS3FileProvider currSS3 = new SS3FileProvider(); // Optional set endpoint //currSS3.setEndpoint(currHost); // Optional set region //currSS3.setRegion(currRegion); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); 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", SS3Constants.S3SCHEME, 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.ftp.TestFtp.java
public static void testFtp() { // System.setProperty("http.proxyHost", "proxy.cls.fr"); // adresse IP // System.setProperty("http.proxyPort", "8080"); // System.setProperty("socksProxyHost", "proxy.cls.fr"); // System.setProperty("socksProxyPort", "1080"); try {//from w w w.jav a 2 s.co m // String user = "anonymous"; // String pass = "email"; // String server = "ftp.cls.fr"; // // FTPClient client = new FTPClient(); // client.connect(server); // System.out.print(client.getReplyString()); // int reply = client.getReplyCode(); // if (!FTPReply.isPositiveCompletion(reply)) // { // throw new IllegalArgumentException("cant connect: " + reply); // } // if (!client.login(user, pass)) // { // throw new IllegalArgumentException("login failed"); // } // client.enterLocalPassiveMode(); // client.disconnect(); FileSystemOptions opts = new FileSystemOptions(); // FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); String server = "proxy.cls.fr"; String user = "anonymous@ftp.unidata.ucar.edu"; String pass = ""; server = "ftp.cls.fr"; user = "anonymous"; pass = "email"; server = "proxy-bureautique.cls.fr"; user = "misgw@ftp.cmcc.it"; pass = "myo2010"; StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pass); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); FileObject fo = VFS.getManager().resolveFile( "ftp://proxy-bureautique.cls.fr/GLOBAL_REANALYSIS_PHYS_001_004_a/global-reanalysis-phys-001-004-a-ran-it-cglors-icemod//global-reanalysis-phys-001-004-a-ran-it-cglors-icemod_20090101_20091231_20110331.nc", opts); FTPClient ftpClient = FtpClientFactory.createConnection(server, 21, user.toCharArray(), pass.toCharArray(), ".", opts); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); // } catch (SocketException e) { // // TODO Auto-generated catch block // e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java
public static void testSftp() { try {//w w w .j a v a 2 s . c om // String user = "anonymous"; // String pass = "email"; // String server = "ftp.cls.fr"; // // FTPClient client = new FTPClient(); // client.connect(server); // System.out.print(client.getReplyString()); // int reply = client.getReplyCode(); // if (!FTPReply.isPositiveCompletion(reply)) // { // throw new IllegalArgumentException("cant connect: " + reply); // } // if (!client.login(user, pass)) // { // throw new IllegalArgumentException("login failed"); // } // client.enterLocalPassiveMode(); // client.disconnect(); FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); // SftpFileSystemConfigBuilder.getInstance().setProxyHost(opts, "proxy.cls.fr"); // SftpFileSystemConfigBuilder.getInstance().setProxyPort(opts, 8080); // SftpFileSystemConfigBuilder.getInstance().setProxyType(opts, // SftpFileSystemConfigBuilder.PROXY_SOCKS5 ); // //SftpFileSystemConfigBuilder.getInstance().setProxyType(opts, // SftpFileSystemConfigBuilder.PROXY_HTTP ); //FileObject fo = VFS.getManager().resolveFile("sftp://t:t@CLS-EARITH.pc.cls.fr/AsciiEnvisat.txt", opts); String server = "CLS-EARITH.pc.cls.fr"; String user = "t"; String pass = "t"; server = "aviso-motu.cls.fr"; user = "mapserv"; pass = "mapserv"; // Session sftpClient = SftpClientFactory.createConnection(server, 22, user.toCharArray(), pass.toCharArray(), opts); Organizer.getUriAsInputStream( "sftp://atoll:atoll@atoll-misgw.vlandata.cls.fr/opt/atoll/misgw-sltac/hoa/publication/inventories/dataset-duacs-ran-global-en-sla-l3__cls-toulouse-fr-sltac-motu-rest.xml"); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); // } catch (SocketException 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(); } }