Example usage for org.apache.commons.vfs VFS getManager

List of usage examples for org.apache.commons.vfs VFS getManager

Introduction

In this page you can find the example usage for org.apache.commons.vfs VFS getManager.

Prototype

public static synchronized FileSystemManager getManager() throws FileSystemException 

Source Link

Document

Returns the default FileSystemManager instance

Usage

From source file:brainflow.core.ImageBrowser.java

public static void main(String[] args) {
    com.jidesoft.utils.Lm.verifyLicense("UIN", "BrainFlow", "S5XiLlHH0VReaWDo84sDmzPxpMJvjP3");
    //com.jidesoft.plaf.LookAndFeelFactory.installDefaultLookAndFeel();
    //LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2007_STYLE);

    URL url1 = BF.getDataURL("data/icbm452_atlas_probability_insula.hdr");
    URL url2 = BF.getDataURL("data/icbm452_atlas_probability_white.hdr");

    try {//from  w w  w .  ja v  a  2s.  c  o m
        UIManager.setLookAndFeel(new NimbusLookAndFeel());
        IImageSource dsource1 = BrainIO.loadDataSource(VFS.getManager().resolveFile(url1.toURI().toString()));
        IImageSource dsource2 = BrainIO.loadDataSource(VFS.getManager().resolveFile(url2.toURI().toString()));
        ImageBrowser browser = new ImageBrowser(Arrays.asList(dsource1, dsource2));
        JFrame frame = new JFrame();
        frame.add(browser, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);

    } catch (Exception e) {
        e.printStackTrace();
    }

    //List<IImageDataSource> dsource2 = BrainIO.loadDataSources(new File("/home/brad/data/sub30072/anat/mprage_anonymized.nii.gz"),
    //                         new File("/home/brad/data/sub54329/anat/mprage_anonymized.nii.gz"));

    // List<List<IImageDataSource>> sourceList = Arrays.asList(dsource1, dsource2);

    // ImageBrowser browser = new ImageBrowser(sourceList);
    //  JFrame frame = new JFrame();
    // frame.add(browser, BorderLayout.CENTER);
    //  frame.pack();
    // frame.setVisible(true);

}

From source file:mondrian.spi.impl.ApacheVfsVirtualFileHandler.java

public InputStream readVirtualFile(String url) throws FileSystemException {
    // Treat catalogUrl as an Apache VFS (Virtual File System) URL.
    // VFS handles all of the usual protocols (http:, file:)
    // and then some.
    FileSystemManager fsManager = VFS.getManager();
    if (fsManager == null) {
        throw Util.newError("Cannot get virtual file system manager");
    }// w  w w .  j  a  va  2  s . co m

    // Workaround VFS bug.
    if (url.startsWith("file://localhost")) {
        url = url.substring("file://localhost".length());
    }
    if (url.startsWith("file:")) {
        url = url.substring("file:".length());
    }

    //work around for VFS bug not closing http sockets
    // (Mondrian-585)
    if (url.startsWith("http")) {
        try {
            return new URL(url).openStream();
        } catch (IOException e) {
            throw Util.newError("Could not read URL: " + url);
        }
    }

    File userDir = new File("").getAbsoluteFile();
    FileObject file = fsManager.resolveFile(userDir, url);
    FileContent fileContent = null;
    try {
        // Because of VFS caching, make sure we refresh to get the latest
        // file content. This refresh may possibly solve the following
        // workaround for defect MONDRIAN-508, but cannot be tested, so we
        // will leave the work around for now.
        file.refresh();

        // Workaround to defect MONDRIAN-508. For HttpFileObjects, verifies
        // the URL of the file retrieved matches the URL passed in.  A VFS
        // cache bug can cause it to treat URLs with different parameters
        // as the same file (e.g. http://blah.com?param=A,
        // http://blah.com?param=B)
        if (file instanceof HttpFileObject && !file.getName().getURI().equals(url)) {
            fsManager.getFilesCache().removeFile(file.getFileSystem(), file.getName());

            file = fsManager.resolveFile(userDir, url);
        }

        if (!file.isReadable()) {
            throw Util.newError("Virtual file is not readable: " + url);
        }

        fileContent = file.getContent();
    } finally {
        file.close();
    }

    if (fileContent == null) {
        throw Util.newError("Cannot get virtual file content: " + url);
    }

    return fileContent.getInputStream();
}

From source file:com.thinkberg.webdav.vfs.VFSBackend.java

private VFSBackend(String rootUri, FileSystemOptions options) throws FileSystemException {
    fileSystemRoot = VFS.getManager().resolveFile(rootUri, options);
}

From source file:com.thinkberg.moxo.vfs.s3.S3FileProviderTest.java

public void testDoCreateFileSystem() throws FileSystemException {
    FileObject object = VFS.getManager().resolveFile(ROOT);
    assertEquals(BUCKETID, ((S3FileName) object.getName()).getRootFile());
}

From source file:com.github.lucapino.sheetmaker.parsers.mediainfo.MediaInfoRetriever.java

@Override
public MovieInfo getMovieInfo(String filePath) {
    MediaInfo mediaInfo = new MediaInfo();
    String fileToParse = filePath;
    // test if we have iso
    if (filePath.toLowerCase().endsWith("iso")) {
        // open iso and parse the ifo files
        Map<Integer, String> ifoFiles = new TreeMap<>();
        try {//from ww  w  .j a v  a2s  .  c om
            FileSystemManager fsManager = VFS.getManager();
            FileObject fo = fsManager.resolveFile("iso:" + filePath + "!/");
            // create an ifo file selector
            FileSelector ifoFs = new FileFilterSelector(new FileFilter() {

                @Override
                public boolean accept(FileSelectInfo fsi) {
                    return fsi.getFile().getName().getBaseName().toLowerCase().endsWith("ifo");
                }
            });
            FileObject[] files = fo.getChild("VIDEO_TS").findFiles(ifoFs);
            for (FileObject file : files) {
                File tmpFile = new File(
                        System.getProperty("java.io.tmpdir") + File.separator + file.getName().getBaseName());
                System.out.println(file.getName().getBaseName());
                IOUtils.copy(file.getContent().getInputStream(), new FileOutputStream(tmpFile));
                mediaInfo.Open(tmpFile.getAbsolutePath());
                String format = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "Format_Profile",
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
                System.out.println("Format profile: " + format);
                // if format is "Program" -> it's a video file
                if (format.equalsIgnoreCase("program")) {
                    String duration = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "Duration",
                            MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
                    System.out.println("Duration: " + duration);
                    ifoFiles.put(Integer.valueOf(duration), tmpFile.getName());
                }
                mediaInfo.Close();
            }
            if (!ifoFiles.isEmpty()) {
                if (ifoFiles.size() == 1) {
                    fileToParse = ifoFiles.values().iterator().next();
                } else {
                    // get the last entry -> the bigger one
                    Set<Integer> keys = ifoFiles.keySet();
                    Iterator<Integer> iterator = keys.iterator();
                    for (int i = 0; i < keys.size(); i++) {
                        String fileName = ifoFiles.get(iterator.next());
                        if (i == keys.size() - 1) {
                            fileToParse = fileName;
                        } else {
                            new File(fileName).delete();
                        }
                    }
                }
            }
        } catch (IOException | NumberFormatException ex) {

        }
    }
    // here fileToParse is correct
    mediaInfo.Open(fileToParse);
    System.out.println(mediaInfo.Inform());

    return new MovieInfoImpl(mediaInfo, filePath);
}

From source file:com.thinkberg.moxo.vfs.s3.S3FileProviderTest.java

public void testRootDirectoryIsFolder() throws FileSystemException {
    FileObject object = VFS.getManager().resolveFile(ROOT);
    assertEquals(FileType.FOLDER, object.getType());
}

From source file:com.panet.imeta.core.vfs.KettleVFS.java

public static FileObject getFileObject(String vfsFilename) throws IOException {
    checkHook();//from ww w  .  j a va  2s . c om

    try {
        FileSystemManager fsManager = VFS.getManager();

        // We have one problem with VFS: if the file is in a subdirectory of the current one: somedir/somefile
        // In that case, VFS doesn't parse the file correctly.
        // We need to put file: in front of it to make it work.
        // However, how are we going to verify this?
        // 
        // We are going to see if the filename starts with one of the known protocols like file: zip: ram: smb: jar: etc.
        // If not, we are going to assume it's a file.
        //
        boolean relativeFilename = true;
        String[] schemes = VFS.getManager().getSchemes();
        for (int i = 0; i < schemes.length && relativeFilename; i++) {
            if (vfsFilename.startsWith(schemes[i] + ":"))
                relativeFilename = false;
        }

        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 = fsManager.resolveFile(filename);

        return fileObject;
    } catch (IOException e) {
        throw new IOException(
                "Unable to get VFS File object for filename '" + vfsFilename + "' : " + e.toString());
    }
}

From source file:com.thinkberg.moxo.vfs.s3.S3FileProviderTest.java

public void testGetDirectory() throws FileSystemException {
    FileObject object = VFS.getManager().resolveFile(ROOT + "/Sites");
    assertEquals(FileType.FOLDER, object.getType());
}

From source file:jfs.sync.vfs.JFSVFSFileProducer.java

/**
 * @return Returns the available schemes.
 *///w w w  .  j ava  2  s.  com
static public String[] getSchemes() {
    ArrayList<String> schemes = new ArrayList<String>();
    String[] schemesArray = new String[0];
    try {
        for (String s : VFS.getManager().getSchemes()) {
            if (!s.equals(JFSConst.SCHEME_LOCAL) && !s.equals(JFSConst.SCHEME_EXTERNAL)) {
                schemes.add(s);
            }
        }
    } catch (FileSystemException e) {
        JFSLog.getErr().getStream().println(e.getLocalizedMessage());
    }
    return schemes.toArray(schemesArray);
}

From source file:jfs.sync.vfs.JFSVFSFileProducer.java

/**
 * Resets the file system manager./* w  w w. j  a  v a2s .  c  o m*/
 */
public void reset() {
    try {
        ((DefaultFileSystemManager) VFS.getManager()).close();
        ((DefaultFileSystemManager) VFS.getManager()).init();
    } catch (FileSystemException e) {
        JFSLog.getErr().getStream().println(e.getLocalizedMessage());
    }
}