Example usage for org.apache.commons.vfs FileSystemManager toFileObject

List of usage examples for org.apache.commons.vfs FileSystemManager toFileObject

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileSystemManager toFileObject.

Prototype

public FileObject toFileObject(File file) throws FileSystemException;

Source Link

Document

Converts a local file into a FileObject .

Usage

From source file:org.kalypso.simulation.grid.TestGridFTP.java

public void testGridFTP() throws Exception {
    final FileSystemManager manager = VFSUtilities.getManager();

    final FileObject remoteRoot = manager.resolveFile("gsiftp://gramd1.gridlab.uni-hannover.de");
    final FileSystem fileSystem = remoteRoot.getFileSystem();
    final String homeDirString = (String) fileSystem.getAttribute(GsiFtpFileProvider.ATTR_HOME_DIR);
    final FileObject homeDir = remoteRoot.resolveFile(homeDirString);
    final String testDirName = "test";
    final FileObject localDir = manager.toFileObject(new File(testDirName));
    final FileObject remoteDir = homeDir.resolveFile(testDirName);
    final FileSynchronizer fileSynchronizer = new FileSynchronizer(localDir, remoteDir);
    fileSynchronizer.updateRemote();/* ww w.ja v a  2  s.  c  o m*/
    fileSynchronizer.updateLocal();
}

From source file:org.kalypso.simulation.grid.TestSimpleGridProcess.java

private void copyFileToWorking(final FileSystemManager manager, final FileObject workingDir,
        final String rmaName) throws IOException, FileSystemException, URISyntaxException {
    final Path path = new Path(rmaName);
    final Bundle bundle = Activator.getDefault().getBundle();
    final URL exeURL = FileLocator.toFileURL(FileLocator.find(bundle, path, null));
    final FileObject exeFile = manager.toFileObject(new File(exeURL.toURI()));
    VFSUtilities.copy(exeFile, workingDir);
}

From source file:org.sakaiproject.assignment2.logic.impl.UploadGradesLogicImpl.java

public List<List<String>> getCSVContent(File file) {
    if (file == null) {
        throw new IllegalArgumentException("Null file passed to uploadGrades");
    }/*from   w  w w . j  av  a2 s . co m*/

    if (!file.getName().endsWith(".csv")) {
        throw new IllegalArgumentException("Uploaded file must be in .csv format");
    }

    List<List<String>> csvContent = new ArrayList<List<String>>();

    try {
        FileSystemManager fsManager = VFS.getManager();
        FileObject gradesFile = fsManager.toFileObject(file);
        FileContent gradesFileContent = gradesFile.getContent();
        csvContent = getCSVContent(gradesFileContent.getInputStream());
    } catch (FileSystemException fse) {
        throw new UploadException("There was an error parsing the data in the csv file", fse);
    }

    return csvContent;
}