de.esprit.common.io

## Class NullInputStream

- java.lang.Object
- - java.io.InputStream
  - - de.esprit.common.io.NullInputStream

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class NullInputStream
      extends java.io.InputStream

  This is an InputStream that generates dummy data for testing purposes. You may override nextByte() in order to specify what data is produced. By default this stream repeats reading the string '0123456789' until it's size is reached.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NullInputStream(int numLines)` Creates an `InputStream` with the given number of lines.
    `NullInputStream(long size)` Creates an `InputStream` with the specified size.
    `NullInputStream(long size, boolean isMarkSupported, boolean isThrowEOF)` Creates an `InputStream` with the specified size.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `available()` Return the number of bytes that are still available in the stream.
    `void` | `close()` Closes and resets this stream.
    `protected int` | `fetchByte()` Return a byte value for the `read()` method.
    `long` | `getPosition()` Return the current position in the stream.
    `long` | `getSize()` Return the size of this `InputStream`.
    `void` | `mark(int readLimit)` Marks the current position.
    `boolean` | `markSupported()` Tells whether mark() is supported.
    `protected byte` | `nextByte()` Is called whenever a byte is read from the stream.
    `int` | `read()` Read the next byte from the stream.
    `int` | `read(byte[] bytes)` Fill bytes into the given array.
    `int` | `read(byte[] bytes, int offset, int length)` Fills the given array from offset with length bytes.
    `void` | `reset()` Reset the stream to the last called mark.
    `long` | `skip(long bytesToSkip)` Skip a specified number of bytes.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NullInputStream

          public NullInputStream(int numLines)

      Creates an `InputStream` with the given number of lines. The size is calculated by adding a platform specific line separator to each line.

    - #### NullInputStream

          public NullInputStream(long size)

      Creates an `InputStream` with the specified size. It supports marking and does not throw EOFException.

    - #### NullInputStream

          public NullInputStream(long size,
                         boolean isMarkSupported,
                         boolean isThrowEOF)

      Creates an `InputStream` with the specified size.
      Parameters:
        `size` - The size of the input stream
        `isMarkSupported` - Tells whether this streams supports mark()
        `isThrowEOF` - throw an `EOFException` when EOF is reached, otherwise return -1.

  - ### Method Detail

    - #### getPosition

          public long getPosition()

      Return the current position in the stream.

    - #### getSize

          public long getSize()

      Return the size of this `InputStream`.

    - #### available

          public int available()

      Return the number of bytes that are still available in the stream.
      Overrides:
        `available` in class `java.io.InputStream`

    - #### close

          public void close()
                     throws java.io.IOException

      Closes and resets this stream.
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### mark

          public void mark(int readLimit)

      Marks the current position.
      Overrides:
        `mark` in class `java.io.InputStream`
      Parameters:
        `readLimit` - the maximum limit of bytes that can be read before the mark position becomes invalid.
      Throws:
        `java.lang.UnsupportedOperationException` - if mark is not supported.

    - #### markSupported

          public boolean markSupported()

      Tells whether mark() is supported.
      Overrides:
        `markSupported` in class `java.io.InputStream`

    - #### read

          public int read()
                   throws java.io.IOException

      Read the next byte from the stream.
      Specified by:
        `read` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### read

          public int read(byte[] bytes)
                   throws java.io.IOException

      Fill bytes into the given array.
      Overrides:
        `read` in class `java.io.InputStream`
      Parameters:
        `bytes` - The byte array to be filled
      Returns:
        The number of bytes or -1 on EOF
      Throws:
        `java.io.IOException`

    - #### read

          public int read(byte[] bytes,
                 int offset,
                 int length)
                   throws java.io.IOException

      Fills the given array from offset with length bytes.
      Overrides:
        `read` in class `java.io.InputStream`
      Parameters:
        `bytes` - The byte array to be filled
      Returns:
        The number of bytes or -1 on EOF
      Throws:
        `java.io.IOException`

    - #### reset

          public void reset()
                     throws java.io.IOException

      Reset the stream to the last called mark.
      Overrides:
        `reset` in class `java.io.InputStream`
      Throws:
        `java.lang.UnsupportedOperationException` - if mark is not supported.
        `java.io.IOException` - If no position has been marked or the read limit has been exceeded since the last position was marked.

    - #### skip

          public long skip(long bytesToSkip)
                    throws java.io.IOException

      Skip a specified number of bytes.
      Overrides:
        `skip` in class `java.io.InputStream`
      Parameters:
        `bytesToSkip` - The number of bytes skipped.
      Returns:
        The number of bytes skipped or -1 when EOF was reached
      Throws:
        `java.io.IOException`

    - #### fetchByte

          protected int fetchByte()

      Return a byte value for the `read()` method.

      This implementation returns zero.

      Returns:
        This implementation always returns zero.

    - #### nextByte

          protected byte nextByte()

      Is called whenever a byte is read from the stream. May be overridden to return test-data other than the default.

Copyright © 2011 EsprIT-Systems. All Rights Reserved.