Search in sources :

Example 11 with FileSystemManager

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();
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Example 12 with FileSystemManager

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());
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException)

Example 13 with FileSystemManager

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();
    }
}
Also used : AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 14 with FileSystemManager

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);
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 15 with FileSystemManager

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;
}
Also used : Vote(org.apache.pivot.util.Vote) Form(org.apache.pivot.wtk.Form) FileName(org.apache.commons.vfs2.FileName) ArrayList(org.apache.pivot.collections.ArrayList) IOException(java.io.IOException) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileSystemManager (org.apache.commons.vfs2.FileSystemManager)30 FileObject (org.apache.commons.vfs2.FileObject)29 FileSystemException (org.apache.commons.vfs2.FileSystemException)21 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)17 File (java.io.File)12 IOException (java.io.IOException)11 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)7 Test (org.junit.Test)6 FileContent (org.apache.commons.vfs2.FileContent)4 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)4 OutputStream (java.io.OutputStream)3 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2