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

com.github.powerlibraries.io.builder.sources.Source Maven / Gradle / Ivy

Go to download

Power Libraries is a small project to collect some repeatedly needed or otherwise useful Java 8 classes in a collection of tiny libraries. IO Power is the first and really tiny library of the Power Libraries. It contains some simple helper method for opening Input- and Outputstreams. The main purpose of IO Power is to make opening streams, readers and writers less cluttered and simple to understand.

The newest version!
package com.github.powerlibraries.io.builder.sources;

import java.io.IOException;
import java.io.InputStream;

/**
 * This class represents a source. A source is a simple wrapper of some kind that is able to open an InputStream. It 
 * may als provide some kind of name that is useful to identify the file content. 
 * @author Manuel Hegner
 */
public interface Source {
	
	/**
	 * This method opens the stream to the source represented by this object. It should be calleable more than once, but
	 * this is not always guaranteed (e.g. InputStreamSource).
	 * @return an InputStream
	 * @throws IOException if opening the InputStream throws an exception
	 */
	public InputStream openStream() throws IOException;

	/**
	 * @return true if this source is able to return a name of any kind
	 */
	public default boolean hasName() {
		return false;
	}

	/**
	 * @return the name of the source if there is any. By default this method throws an {@link UnsupportedOperationException}.
	 */
	public default String getName() {
		throw new UnsupportedOperationException();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy