Search in sources :

Example 1 with FolderConnection

use of com.revolsys.io.file.FolderConnection in project com.revolsys.open by revolsys.

the class FileUtil method getFile.

public static File getFile(URI uri) {
    final String scheme = uri.getScheme();
    if ("folderconnection".equalsIgnoreCase(scheme)) {
        final String authority = uri.getAuthority();
        final String connectionName = UrlUtil.percentDecode(authority);
        final String path = uri.getPath();
        File file = null;
        for (final FolderConnectionRegistry registry : FileConnectionManager.get().getConnectionRegistries()) {
            final FolderConnection connection = registry.getConnection(connectionName);
            if (connection != null) {
                final File directory = connection.getFile();
                file = new File(directory, path);
                if (file.exists()) {
                    return getFile(file);
                }
            }
        }
        return file;
    } else if ("file".equalsIgnoreCase(scheme)) {
        try {
            uri = new URI(scheme, uri.getPath(), null);
        } catch (final URISyntaxException e) {
        }
        return getFile(new File(uri));
    } else {
        throw new IllegalArgumentException("file URL expected: " + uri);
    }
}
Also used : FolderConnectionRegistry(com.revolsys.io.file.FolderConnectionRegistry) FolderConnection(com.revolsys.io.file.FolderConnection) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

Aggregations

FolderConnection (com.revolsys.io.file.FolderConnection)1 FolderConnectionRegistry (com.revolsys.io.file.FolderConnectionRegistry)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1