use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSUtils method isFailRecord.
public static boolean isFailRecord(FileSystemManager fsManager, FileObject fo, FileSystemOptions fso) {
try {
String fullPath = fo.getName().getURI();
String queryParams = "";
int pos = fullPath.indexOf('?');
if (pos > -1) {
queryParams = fullPath.substring(pos);
fullPath = fullPath.substring(0, pos);
}
FileObject failObject = fsManager.resolveFile(fullPath + FAIL_FILE_SUFFIX + queryParams, fso);
if (failObject.exists()) {
return true;
}
} catch (FileSystemException e) {
log.error("Couldn't release the fail for the file : " + maskURLPassword(fo.getName().getURI()));
}
return false;
}
use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSTransportSenderTest method getSoftReferenceMap.
private Map<?, ?> getSoftReferenceMap(VFSTransportSender vfsTransportSender) throws NoSuchFieldException, IllegalAccessException {
Field field = VFSTransportSender.class.getDeclaredField("fsManager");
field.setAccessible(true);
FileSystemManager fsm = (FileSystemManager) field.get(vfsTransportSender);
FilesCache fileCache = fsm.getFilesCache();
SoftRefFilesCache softRefFilesCache = (SoftRefFilesCache) fileCache;
Field field1 = SoftRefFilesCache.class.getDeclaredField("refReverseMap");
field1.setAccessible(true);
return (Map<?, ?>) (Map) field1.get(softRefFilesCache);
}
use of org.apache.commons.vfs2.FileSystemManager in project pentaho-platform by pentaho.
the class PentahoXmlaServlet method makeCatalogLocator.
@Override
protected CatalogLocator makeCatalogLocator(ServletConfig servletConfig) {
return new ServletContextCatalogLocator(servletConfig.getServletContext()) {
@Override
public String locate(String catalogPath) {
if (catalogPath.startsWith("mondrian:")) {
// $NON-NLS-1$
try {
FileSystemManager fsManager = VFS.getManager();
SolutionRepositoryVfsFileObject catalog = (SolutionRepositoryVfsFileObject) fsManager.resolveFile(catalogPath);
catalogPath = "solution:" + catalog.getFileRef();
} catch (FileSystemException e) {
logger.error(e.getMessage());
}
} else {
catalogPath = super.locate(catalogPath);
}
return catalogPath;
}
};
}
use of org.apache.commons.vfs2.FileSystemManager in project javautils by jiadongpo.
the class SFTPClientVFS method getFileObject.
public static FileObject getFileObject(String vfsFilename) throws Exception {
try {
FileSystemManager fsManager = getInstance().getFileSystemManager();
boolean relativeFilename = true;
String[] schemes = fsManager.getSchemes();
for (int i = 0; i < schemes.length && relativeFilename; i++) {
if (vfsFilename.startsWith(schemes[i] + ":")) {
relativeFilename = false;
// We have a VFS URL, load any options for the file system driver
// fsOptions = buildFsOptions( space, fsOptions, vfsFilename, schemes[i] );
}
}
String filename;
if (vfsFilename.startsWith("\\\\")) {
File file = new File(vfsFilename);
filename = file.toURI().toString();
} else {
if (relativeFilename) {
File file = new File(vfsFilename);
filename = file.getAbsolutePath();
} else {
filename = vfsFilename;
}
}
FileObject fileObject = null;
return fsManager.resolveFile(filename);
} catch (IOException e) {
throw new Exception("Unable to get VFS File object for filename '" + cleanseFilename(vfsFilename) + "' : " + e.getMessage());
}
}
use of org.apache.commons.vfs2.FileSystemManager in project javautils by jiadongpo.
the class FtpVFS method testsftp.
/**
* 测试末通过
*
* @throws Exception
*/
public void testsftp() throws Exception {
FileSystemManager fsManager = VFS.getManager();
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
// 显示目录
FileObject fo = fsManager.resolveFile("sftp://ci:Zj4xyBkgjd@10.151.30.10:22/apps/tomcat7-40-tomcat-air-ticket-merchant/logs/", opts);
// 得到远程文件列表
FileObject[] children = fo.getChildren();
for (int i = 0; i < children.length; i++) {
FileObject f = children[i];
FileContent c = f.getContent();
File localFile = new File(f.getName().getBaseName());
FileOutputStream out = new FileOutputStream(localFile);
// 写入本地
org.apache.commons.io.IOUtils.copy(c.getInputStream(), out);
// 或使用写入
FileObject obj = fsManager.resolveFile(this.getTargetResourceURL() + f.getName().getBaseName());
if (!obj.exists()) {
obj.createFile();
obj.copyFrom(f, Selectors.SELECT_SELF);
}
final long size = (f.getType() == FileType.FILE) ? c.getSize() : -1;
final long date = (f.getType() == FileType.FILE) ? c.getLastModifiedTime() : -1;
System.out.println(f.getName().getPath() + " date:" + date + " Size:" + size);
}
}
Aggregations