001package io.cui.tools.io;
002
003import java.io.IOException;
004import java.io.InputStream;
005import java.io.Serializable;
006import java.net.URL;
007
008/**
009 * Wraps different ways file loading: FileSystem (absolute), Classpath,..
010 * <p>
011 * The implementations must be reentrant regarding {@link #inputStream()}
012 * </p>
013 *
014 * @author Oliver Wolff
015 */
016public interface FileLoader extends Serializable {
017
018    /**
019     * @return boolean indicating whether the concrete file exists and is accessible
020     */
021    boolean isReadable();
022
023    /**
024     * @return the filename in an appropriate presentation.
025     */
026    StructuredFilename getFileName();
027
028    /**
029     * This method should be within a {@code try-with-resources} statement as it is not closed by
030     * the implementation.
031     *
032     * @return an {@link InputStream} on the corresponding file. It implicitly checks
033     *         {@link #isReadable()} before accessing the file and will throw an
034     *         {@link IllegalStateException} in case it is not readable.
035     * @throws IOException
036     */
037    InputStream inputStream() throws IOException;
038
039    /**
040     * @return an {@link URL} on the corresponding file.
041     */
042    URL getURL();
043
044    /**
045     * @return boolean indicating that the loader loads from the file-system and not from the
046     *         classpath
047     */
048    boolean isFilesystemLoader();
049}