All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.oneandone.sushi.fs.timemachine.TimeMachineNode Maven / Gradle / Ivy

/*
 * Copyright 1&1 Internet AG, https://github.com/1and1/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.oneandone.sushi.fs.timemachine;

import net.oneandone.sushi.fs.CopyFileFromException;
import net.oneandone.sushi.fs.CopyFileToException;
import net.oneandone.sushi.fs.DeleteException;
import net.oneandone.sushi.fs.DirectoryNotFoundException;
import net.oneandone.sushi.fs.ExistsException;
import net.oneandone.sushi.fs.FileNotFoundException;
import net.oneandone.sushi.fs.Filesystem;
import net.oneandone.sushi.fs.GetLastModifiedException;
import net.oneandone.sushi.fs.LinkException;
import net.oneandone.sushi.fs.ListException;
import net.oneandone.sushi.fs.MkdirException;
import net.oneandone.sushi.fs.MoveException;
import net.oneandone.sushi.fs.NewInputStreamException;
import net.oneandone.sushi.fs.Node;
import net.oneandone.sushi.fs.ReadLinkException;
import net.oneandone.sushi.fs.SetLastModifiedException;
import net.oneandone.sushi.fs.SizeException;
import net.oneandone.sushi.fs.file.FileNode;
import net.oneandone.sushi.fs.zip.ZipNode;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.attribute.GroupPrincipal;
import java.nio.file.attribute.UserPrincipal;
import java.util.ArrayList;
import java.util.List;

public class TimeMachineNode extends Node {
    private final TimeMachineRoot root;
    private final FileNode node;
    private final String path;

    // CAUTION: url is not checked for url parameter
    public TimeMachineNode(TimeMachineRoot root, FileNode node, String path) {
        this.root = root;
        this.node = node;
        this.path = path;
    }

    @Override
    public TimeMachineRoot getRoot() {
        return root;
    }

    @Override
    public long size() throws SizeException {
        return node.size();
    }

    @Override
    public long getLastModified() throws GetLastModifiedException {
        return node.getLastModified();
    }

    @Override
    public void setLastModified(long millis) throws SetLastModifiedException {
        throw new SetLastModifiedException(this);
    }

    @Override
    public String getPermissions() {
        throw unsupported("getPermissions()");
    }

    @Override
    public void setPermissions(String permissions) {
        throw unsupported("setPermissions()");
    }

    @Override
    public UserPrincipal getOwner() {
        throw unsupported("getOwner()");
    }

    @Override
    public void setOwner(UserPrincipal owner) {
        throw unsupported("setOwner()");
    }

    @Override
    public GroupPrincipal getGroup() {
        throw unsupported("getGroup()");
    }

    @Override
    public void setGroup(GroupPrincipal group) {
        throw unsupported("setGroup()");
    }

    @Override
    public String getPath() {
        return path;
    }


    @Override
    public TimeMachineNode deleteFile() throws DeleteException {
        throw unsupported("deleteFile()");
    }

    @Override
    public TimeMachineNode deleteDirectory() throws DeleteException {
        throw unsupported("deleteDirectory()");
    }

    @Override
    public TimeMachineNode deleteTree() throws DeleteException {
        throw unsupported("deleteTree()");
    }

    @Override
    public ZipNode move(Node dest, boolean overwrite) throws MoveException {
        throw unsupported("move()");
    }

    @Override
    public TimeMachineNode mkdir() throws MkdirException {
        throw unsupported("delete");
    }

    @Override
    public void mklink(String target) throws LinkException {
        node.mklink(target);
    }

    @Override
    public String readLink() throws ReadLinkException {
        return node.readLink();
    }

    @Override
    public boolean exists() throws ExistsException {
        return node.exists();
    }

    @Override
    public boolean isFile() throws ExistsException {
        return node.isFile();
    }

    @Override
    public boolean isDirectory() throws ExistsException {
        return node.isDirectory();
    }

    @Override
    public boolean isLink() throws ExistsException {
    	return node.isLink();
    }

    @Override
    public InputStream newInputStream() throws FileNotFoundException, NewInputStreamException {
        return node.newInputStream();
    }

    public long copyFileTo(OutputStream dest, long skip) throws FileNotFoundException, CopyFileToException {
        return copyFileToImpl(dest, skip);
    }

    public void copyFileFrom(InputStream dest) throws FileNotFoundException, CopyFileFromException {
        copyFileFromImpl(dest);
    }

    @Override
    public OutputStream newOutputStream(boolean append) {
        throw unsupported("newOutputStream(boolean)");
    }

    @Override
    public List list() throws ListException, DirectoryNotFoundException {
        List files;
        List result;
        Filesystem fs;

        files = node.list();
        if (files == null) {
            return null;
        }
        result = new ArrayList<>(files.size());
        fs = root.getFilesystem();
        for (FileNode file : files) {
            try {
                result.add(new TimeMachineNode(root, root.resolve(file), fs.join(path, file.getName())));
            } catch (IOException e) {
                throw new ListException(this, e);
            }
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy