use of org.apache.commons.vfs2.FileSystemManager in project javautils by jiadongpo.
the class FtpVFS method testftp.
public void testftp() throws Exception {
FileSystemManager manager;
try {
manager = VFS.getManager();
FileObject ftpFile = manager.resolveFile("ftp://ci:Zj4xyBkgjd@10.151.30.10:21/apps/tomcat7-40-tomcat-air-ticket-merchant/logs");
FileObject[] children = ftpFile.getChildren();
System.out.println("Children of " + ftpFile.getName().getURI());
for (FileObject child : children) {
String baseName = child.getName().getBaseName();
System.out.println("文件名(中文):" + baseName + " -- " + new String(baseName.getBytes("iso-8859-1"), "UTF-8"));
}
} catch (FileSystemException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
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 artisynth_core by artisynth.
the class ZipUtility method unzip.
public static void unzip(URIx src, final File dest) throws IOException {
dest.mkdirs();
final FileSystemManager fileSystemManager = VFS.getManager();
final FileObject zipFileObject = fileSystemManager.resolveFile(src.toString());
try {
final FileObject fileSystem = fileSystemManager.createFileSystem(zipFileObject);
try {
fileSystemManager.toFileObject(dest).copyFrom(fileSystem, new AllFileSelector());
} finally {
fileSystem.close();
}
} finally {
zipFileObject.close();
}
}
use of org.apache.commons.vfs2.FileSystemManager in project pivot by apache.
the class VFSBrowserSheet method setManager.
public void setManager(FileSystemManager manager) throws FileSystemException {
FileSystemManager previousManager = this.manager;
if (manager == null) {
this.manager = VFS.getManager();
} else {
this.manager = manager;
}
FileObject baseFile = this.manager.getBaseFile();
if (baseFile != null) {
baseFileName = baseFile.getName();
}
if (previousManager != null && previousManager != this.manager) {
fileBrowserSheetListeners.managerChanged(this, previousManager);
}
}
use of org.apache.commons.vfs2.FileSystemManager in project pivot by apache.
the class TerraVFSBrowserSheetSkin method previewSheetClose.
@Override
public Vote previewSheetClose(final Sheet sheet, final boolean result) {
Vote vote = null;
if (result && !okButton.isEnabled()) {
vote = Vote.DENY;
} else {
if (result) {
updatingSelection = true;
VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) sheet;
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
FileSystemManager manager = fileBrowserSheet.getManager();
FileName baseFileName = fileBrowserSheet.getBaseFileName();
switch(mode) {
case OPEN:
case OPEN_MULTIPLE:
case SAVE_TO:
{
try {
fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
break;
}
case SAVE_AS:
{
String fileName = saveAsTextInput.getText();
// current location and let the chips fall ...
try {
FileObject selectedFile = manager.resolveFile(fileBrowser.getRootDirectory(), fileName);
// !fileName.startsWith(File.separator)) {
if (selectedFile.exists() && selectedFile.getType() == FileType.FOLDER) {
try {
// TODO: what to do about canonical file representations?
FileObject root = /* selectedFile.getCanonicalFile(); */
selectedFile;
fileBrowserSheet.setRootDirectory(root);
fileBrowser.setRootDirectory(root);
setHostLabel(root);
saveAsTextInput.setText("");
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
}
selectedFile = null;
vote = Vote.DENY;
} else {
FileObject root = selectedFile.getParent();
if (root != null && root.exists() && root.getType() == FileType.FOLDER) {
try {
// TODO: canonical file again
// fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
fileBrowserSheet.setRootDirectory(root);
setHostLabel(root);
selectedFile = manager.resolveFile(selectedFile.getName().getURI());
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
selectedFile = null;
vote = Vote.DENY;
}
} else {
// Could be an error message here
// ("Directory does not exist")
Form.setFlag(saveAsBoxPane, new Form.Flag());
selectedFile = null;
vote = Vote.DENY;
}
}
if (selectedFile != null) {
fileBrowserSheet.setSelectedFiles(new ArrayList<>(selectedFile));
}
} catch (FileSystemException fse) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
vote = Vote.DENY;
}
break;
}
default:
break;
}
updatingSelection = false;
}
if (vote == null) {
vote = super.previewSheetClose(sheet, result);
}
}
return vote;
}
Aggregations