sf.net.experimaestro.sshfs.SshFileSystem.java Source code

Java tutorial

Introduction

Here is the source code for sf.net.experimaestro.sshfs.SshFileSystem.java

Source

package sf.net.experimaestro.sshfs;

/*
 * This file is part of experimaestro.
 * Copyright (c) 2014 B. Piwowarski <benjamin@bpiwowar.net>
 *
 * experimaestro is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * experimaestro is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with experimaestro.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.apache.commons.lang.NotImplementedException;

import java.io.IOException;
import java.net.URI;
import java.nio.file.*;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.spi.FileSystemProvider;
import java.util.Set;

/**
 * An SSH file system
 */
public class SshFileSystem extends FileSystem {
    public static final String PATH_SEPARATOR = "/";
    public static SshFileSystem instance = new SshFileSystem();

    @Override
    public FileSystemProvider provider() {
        return SshFileSystemProvider.instance;
    }

    @Override
    public void close() throws IOException {
    }

    @Override
    public boolean isOpen() {
        return true;
    }

    @Override
    public boolean isReadOnly() {
        return false;
    }

    @Override
    public String getSeparator() {
        return PATH_SEPARATOR;
    }

    @Override
    public Iterable<Path> getRootDirectories() {
        throw new NotImplementedException();
    }

    /**
     * Each store corresponds to one network share
     * @return
     */
    @Override
    public Iterable<FileStore> getFileStores() {
        // Should return the list of network shares
        throw new NotImplementedException();
    }

    @Override
    public Set<String> supportedFileAttributeViews() {
        throw new NotImplementedException();
    }

    @Override
    public Path getPath(String first, String... more) {
        if (more == null || more.length == 0) {
            return new SshPath(this, null, first);
        }

        StringBuilder builder = new StringBuilder(first);
        for (String part : more) {
            builder.append(PATH_SEPARATOR).append(part);
        }
        return new SshPath(this, null, builder.toString());
    }

    @Override
    public PathMatcher getPathMatcher(String syntaxAndPattern) {
        throw new NotImplementedException();
    }

    @Override
    public UserPrincipalLookupService getUserPrincipalLookupService() {
        throw new NotImplementedException();
    }

    @Override
    public WatchService newWatchService() throws IOException {
        throw new NotImplementedException();
    }

    public Path getPath(URI uri) {
        return new SshPath(this, uri.getHost(), uri.getPath());
    }
}