Package info.jjhop.deimos

Source Code of info.jjhop.deimos.DeimosRepository

package info.jjhop.deimos;

import java.io.File;
import java.io.InputStream;

import info.jjhop.deimos.repository.FSRepositoryImpl;
import info.jjhop.deimos.repository.MemoryRepositoryImpl;
import info.jjhop.deimos.repository.Repository;

public class DeimosRepository {

    private final Repository repository;

    public DeimosRepository() {
        this.repository = new MemoryRepositoryImpl();
    }

    public DeimosRepository(File repositoryDir) {
        checkDirectory(repositoryDir);
        this.repository = new FSRepositoryImpl(repositoryDir);
    }

    public boolean fileExists(String name, String digest) {
        return repository.fileExists(name, digest);
    }

    public String store(File file) {
        return repository.store(file);
    }

    public boolean store(File file, String digest) {
        return repository.store(file, digest);
    }

    public boolean store(InputStream stream, String name, String digest) {
        return repository.store(stream, name, digest);
    }

    public String store(InputStream stream, String name) {
        return repository.store(stream, name);
    }

    public InputStream getInputStream(String name, String digest) {
        return repository.getInputStream(name, digest);
    }

    public boolean delete(String name, String digest) {
        return repository.delete(name, digest);
    }

    public Repository.Type getType() {
        return repository.getType();
    }

    private void checkDirectory(File directory) {
        if (directory == null) {
            throw new IllegalArgumentException("Directory may not be null.");
        }
        if (directory.exists() && !directory.isDirectory()) {
            throw new RuntimeException("Can't create repository in file, only dir allowed.");
        }
        if (directory.exists() && !directory.canWrite()) {
            throw new RuntimeException("Can't create repository without write permission.");
        }
    }
}
TOP

Related Classes of info.jjhop.deimos.DeimosRepository

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.