List of usage examples for org.apache.commons.vfs2.impl DefaultFileSystemManager close
public void close()
From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java
public static void uploadFile(String accntName, String acctHost, String accntKey, String containerName, Path localFile, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init();//from w w w.ja va 2 s .c o m StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, acctHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile)); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); currFile.close(); currMan.close(); }
From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java
public static void uploadFile(String accntName, String accntHost, String accntKey, String containerName, Path localFile, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init();//from w ww. j a va2 s . c o m StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile)); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); currFile.close(); currMan.close(); }
From source file:com.seer.datacruncher.services.scheduler.PlannerSetStatusJob.java
private boolean checkServiceRunning(ConnectionsEntity conn) { boolean success = true; String url = ""; DefaultFileSystemManager fsManager = null; String userName = ""; String password = ""; String hostName = ""; String port = ""; String inputDirectory = ""; String fileName = ""; if (conn != null) { userName = conn.getUserName();// w w w. jav a 2 s .c om password = conn.getPassword(); hostName = conn.getHost(); port = conn.getPort(); inputDirectory = conn.getDirectory(); fileName = conn.getFileName(); } if (conn.getIdConnType() == GenericType.DownloadTypeConn) { if (fileName == null || fileName.trim().length() == 0) { return false; } inputDirectory = inputDirectory + "/" + fileName; } try { fsManager = (DefaultFileSystemManager) VFS.getManager(); if (conn.getService() == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory; } else if (conn.getService() == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory; } else if (conn.getService() == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new FtpFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory; } final FileObject fileObject = fsManager.resolveFile(url); if (fileObject == null || !fileObject.exists()) { success = false; } } catch (Exception ex) { success = false; } finally { if (fsManager != null) fsManager.close(); } return success; }
From source file:com.seer.datacruncher.spring.ConnectionsFileDownloadController.java
private String getFileContent(long connId, ConnectionsEntity connectionEntity) { String content = ""; DefaultFileSystemManager fsManager = null; FileObject fileObject = null; try {// w ww .ja v a 2 s . c om fsManager = (DefaultFileSystemManager) VFS.getManager(); int serviceId = connectionEntity.getService(); String hostName = connectionEntity.getHost(); String port = connectionEntity.getPort(); String userName = connectionEntity.getUserName(); String password = connectionEntity.getPassword(); String inputDirectory = connectionEntity.getDirectory(); String fileName = connectionEntity.getFileName(); log.info("Trying to Server polling at server [" + hostName + ":" + port + "] with user[" + userName + "]."); String url = ""; if (serviceId == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName; } else if (serviceId == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName; } else if (serviceId == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new SmbFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName; } fileObject = fsManager.resolveFile(url); if (fileObject == null || !fileObject.exists() || fileObject.getType().equals(FileType.IMAGINARY)) { return null; } BufferedReader fileReader = new BufferedReader( new InputStreamReader(fileObject.getContent().getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = fileReader.readLine()) != null) { sb.append(line); } content = sb.toString(); } catch (Exception ex) { } finally { try { if (fileObject != null) { fileObject.close(); } if (fsManager != null) { fsManager.freeUnusedResources(); fsManager.close(); fsManager = null; } } catch (Exception ex) { } finally { fileObject = null; fsManager = null; } } return content; }
From source file:com.seer.datacruncher.spring.IsSuccessfulConnectionController.java
private String checkServiceRunning(int service, String connID) { String success = "true"; String url = ""; ConnectionsEntity conn = connectionsDao.find(Long.parseLong(connID)); DefaultFileSystemManager fsManager = null; FileObject fileObject = null; String userName = ""; String password = ""; String hostName = ""; String port = ""; String inputDirectory = ""; String fileName = ""; int connType = 1; if (conn != null) { userName = conn.getUserName();//from www . ja v a 2 s . c om password = conn.getPassword(); hostName = conn.getHost(); port = conn.getPort(); inputDirectory = conn.getDirectory(); fileName = conn.getFileName(); connType = conn.getIdConnType(); } if (connType == GenericType.DownloadTypeConn) { if (fileName == null || fileName.trim().length() == 0) { return "false"; } else { fileName = "/" + fileName; } } else { fileName = ""; } try { fsManager = (DefaultFileSystemManager) VFS.getManager(); if (service == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + fileName; } else if (service == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory + fileName; } else if (service == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new FtpFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + fileName; } fileObject = fsManager.resolveFile(url); if (fileObject == null || !fileObject.exists()) { success = "false"; } if (connType == GenericType.DownloadTypeConn) { if (fileObject.getType().equals(FileType.IMAGINARY)) { success = "false"; } byte data[] = new byte[(int) fileObject.getContent().getSize()]; fileObject.getContent().getInputStream().read(data); } } catch (Exception ex) { success = "false"; } finally { try { if (fileObject != null) { fileObject.close(); } if (fsManager != null) { fsManager.freeUnusedResources(); fsManager.close(); fsManager = null; } } catch (Exception ex) { } finally { fileObject = null; fsManager = null; } } return success; }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader.java
public static void close() { for (WeakReference<DefaultFileSystemManager> vfsInstance : vfsInstances) { DefaultFileSystemManager ref = vfsInstance.get(); if (ref != null) { FileReplicator replicator;/*from w w w. j av a 2 s.com*/ try { replicator = ref.getReplicator(); if (replicator instanceof UniqueFileReplicator) { ((UniqueFileReplicator) replicator).close(); } } catch (FileSystemException e) { log.error("FileSystemException", e); } ref.close(); } } try { FileUtils.deleteDirectory(computeTopCacheDir()); } catch (IOException e) { log.error("IOException", e); } }