package de.siphalor.was.content.resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * A file based implementation for {@link Resource}.
 */
public class FileResource extends Resource {
	/**
	 * The file that this resource points to
	 */
	private final File file;

	/**
	 * Constructs a new file resource
	 * @param id The id to use
	 * @param file The file to point to
	 */
	public FileResource(String id, File file) {
		super(id);
		this.file = file;
	}

	/**
	 * Opens a new {@link FileInputStream} to the contained file.
	 * @return The input stream or <code>null</code> if opening the stream failed
	 */
	@Override
	public InputStream getInputStream() {
		try {
			return new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
}
