package net.ranides.assira.io.uri.impl;

import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.io.uri.URIHandle;
import net.ranides.assira.io.uri.URIResolver;
import net.ranides.assira.io.uri.URITime;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.Instant;

/**
 * Basic implementation used to represent non existing resource.
 *
 * Of course, most implementations can represent invalid resources anyway.
 *
 * @author msieron
 */
class CInvalidHandle extends CHandle {

    private static final String NFE = "File not found: ";

    private final URIResolver resolver;
    private final URI uri;

    public CInvalidHandle(URIResolver resolver, URI uri) {
        this.resolver = resolver;
        this.uri = uri;
    }

    @Override
    public URIResolver resolver() {
        return resolver;
    }

    @Override
    public URI uri() {
        return uri;
    }

    @Override
    public Instant time(URITime ut) throws IOException {
        throw new IOException(NFE + uri);
    }

    @Override
    public long size() throws IOException {
        throw new IOException(NFE + uri);
    }

    @Override
    public CQuery<URIHandle> scan() throws IOException {
        throw new IOException(NFE + uri);
    }

    @Override
    public InputStream istream() throws IOException {
        throw new IOException(NFE + uri);
    }

    @Override
    public void copy(URIHandle target) throws IOException {
        throw new IOException(NFE + uri);
    }

}
