//============================================================================== // NullInputStream.java //============================================================================== package tribble.io; // System imports import java.io.InputStream; import java.io.IOException; import java.lang.String; // Local imports // (None) /******************************************************************************* * Null input stream. * *
* A stream which contains no data, i.e., it always returns end-of-file when * attempts are made to read from it. This is similar to the Unix/POSIX * /dev/null device or the MS-DOS nul file. * *
* Note that none of the methods throw an IOException.
*
*
* @version $Revision: 1.2 $ $Date: 2005/04/06 03:31:02 $
* @since 2005-04-05
* @author
* David R. Tribble
* (david@tribble.com).
*
*
* Copyright ©2005 by David R. Tribble, all rights reserved.
*
* Permission is granted to freely use and distribute this source
* code provided that the original copyright and authorship notices
* remain intact.
*
* @see NullOutputStream
*/
public class NullInputStream
extends java.io.InputStream
{
// Identification
/** Revision information. */
static final String REV =
"@(#)tribble/io/NullInputStream.java $Revision: 1.2 $ $Date: 2005/04/06 03:31:02 $\n";
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Public static variables
/** A null input stream. */
public static NullInputStream NULL_IN =
new NullInputStream();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Public constructors
/***************************************************************************
* Default constructor.
*
* @since 1.1, 2005-04-05
*/
public NullInputStream()
{
// Initialize
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Public methods
/***************************************************************************
* Read a byte from this (empty) stream.
*
*
* Note that this method never throws an IOException. * * @return * -1 always, indication no more input is available. * * @since 1.1, 2005-04-05 */ public int read() { // Empty stream return (-1); } /*************************************************************************** * Read a set of bytes from this (empty) stream. * *
* Note that this method never throws an IOException. * * @param buf * An array of bytes to be read. * The contents of this are not modified. * * @return * -1 always, indication no more input is available. * * @since 1.1, 2005-04-05 */ public int read(byte[] buf) { // Empty stream return (-1); } /*************************************************************************** * Read a set of bytes from this (empty) stream. * *
* Note that this method never throws an IOException. * * @param buf * An array of bytes to be read. * The contents of this are not modified. * * @param off * Index of the first byte in buf to read. * * @param len * Number of bytes in buf to read. * This is ignored. * * @return * -1 always, indication no more input is available. * * @since 1.1, 2005-04-05 */ public int read(byte[] buf, int off, int len) { // Empty stream return (-1); } /*************************************************************************** * Skip (discard) a number of bytes from this (empty) stream. * *
* Note that this method never throws an IOException. * * @param n * The number of input bytes to skip. * * @return * The number of bytes skipped, which is always n. * * @since 1.1, 2005-04-05 */ public long skip(long n) { // Empty stream return (n); } } // End NullInputStream.java