use of org.apache.commons.vfs2.FileSystemManager in project spoofax by metaborg.
the class ResourceService method close.
@Override
public void close() {
if (fileSystemManager instanceof DefaultFileSystemManager) {
final DefaultFileSystemManager defaultFileSystemManager = (DefaultFileSystemManager) fileSystemManager;
defaultFileSystemManager.close();
} else {
logger.warn("File system manager {} does not support cleaning up", fileSystemManager);
}
}
use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSUtils method releaseFail.
public static void releaseFail(FileSystemManager fsManager, FileObject fo) {
try {
String fullPath = fo.getName().getURI();
int pos = fullPath.indexOf("?");
if (pos > -1) {
fullPath = fullPath.substring(0, pos);
}
FileObject failObject = fsManager.resolveFile(fullPath + ".fail");
if (failObject.exists()) {
failObject.delete();
}
} catch (FileSystemException e) {
log.error("Couldn't release the fail for the file : " + maskURLPassword(fo.getName().getURI()));
}
}
use of org.apache.commons.vfs2.FileSystemManager in project javautils by jiadongpo.
the class FtpVFS method testftp2.
public void testftp2() throws Exception {
FileSystemManager fsManager = VFS.getManager();
FileObject fo = fsManager.resolveFile("ftp://ci:Zj4xyBkgjd@10.151.30.10:21/apps/tomcat7-40-tomcat-air-ticket-merchant/logs");
// 得到远程文件列表
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);
}
}
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 accumulo by apache.
the class AccumuloVFSClassLoaderTest method testDefaultCacheDirectory.
@Test
public void testDefaultCacheDirectory() throws Exception {
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
File conf = folder1.newFile("accumulo-site.xml");
FileWriter out = new FileWriter(conf);
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.append("<configuration>\n");
out.append("<property>\n");
out.append("<name>general.classpaths</name>\n");
out.append("<value></value>\n");
out.append("</property>\n");
out.append("<property>\n");
out.append("<name>general.vfs.classpaths</name>\n");
out.append("<value></value>\n");
out.append("</property>\n");
out.append("</configuration>\n");
out.close();
Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
AccumuloVFSClassLoader.getClassLoader();
FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
File tempDir = Whitebox.getInternalState(replicator, "tempDir");
String tempDirParent = tempDir.getParent();
String tempDirName = tempDir.getName();
String javaIoTmpDir = System.getProperty("java.io.tmpdir");
// trim off any final separator, because java.io.File does the same.
if (javaIoTmpDir.endsWith(File.separator)) {
javaIoTmpDir = javaIoTmpDir.substring(0, javaIoTmpDir.length() - File.separator.length());
}
Assert.assertTrue(javaIoTmpDir.equals(tempDirParent));
Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
Aggregations