001/* 002 * Copyright 2023 the original author or authors. 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.tools.io; 017 018import java.io.IOException; 019import java.io.InputStream; 020import java.io.Serializable; 021import java.net.URL; 022 023/** 024 * Wraps different ways file loading: FileSystem (absolute), Classpath,.. 025 * <p> 026 * The implementations must be reentrant regarding {@link #inputStream()} 027 * </p> 028 * 029 * @author Oliver Wolff 030 */ 031public interface FileLoader extends Serializable { 032 033 /** 034 * @return boolean indicating whether the concrete file exists and is accessible 035 */ 036 boolean isReadable(); 037 038 /** 039 * @return the filename in an appropriate presentation. 040 */ 041 StructuredFilename getFileName(); 042 043 /** 044 * This method should be within a {@code try-with-resources} statement as it is 045 * not closed by the implementation. 046 * 047 * @return an {@link InputStream} on the corresponding file. It implicitly 048 * checks {@link #isReadable()} before accessing the file and will throw 049 * an {@link IllegalStateException} in case it is not readable. 050 * @throws IOException 051 */ 052 InputStream inputStream() throws IOException; 053 054 /** 055 * @return an {@link URL} on the corresponding file. 056 */ 057 URL getURL(); 058 059 /** 060 * @return boolean indicating that the loader loads from the file-system and not 061 * from the classpath 062 */ 063 boolean isFilesystemLoader(); 064}