Class TextInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class TextInputStream
    extends ByteArrayInputStream

    A simple stream for reading text. This class is a simple addition to the ByteArrayInputStream class that it implements: it allows the addition of strings. This allows text to be appended to the stream after creation, which can be helpful for a multitude of reasons. However, we will be using it for the simple reason that it allows us to have an InputStream that can receive a simple string as input, and dynamically modify that stream.

    Since:
    JTalker 0.2.0
    Version:
    0.0.1
    Author:
    C. William Oswald
    • Constructor Detail

      • TextInputStream

        public TextInputStream​(byte[] buf)
        Creates a TextInputStream so that it uses buf as its buffer array. The buffer array is not copied. The initial value of pos is 0 and the initial value of count is the length of buf.
      • TextInputStream

        public TextInputStream​(byte[] buf,
                               int offset,
                               int length)
        Creates a TextInputStream that uses buf as its buffer array. The initial value of pos is offset and the initial value of count is the minimum of offset + length and buf.length. The buffer array is not copied. The buffer's mark is set to the specified offset.
      • TextInputStream

        public TextInputStream​(String s)
        Creates a stream with the given String as the starting bytes.
        Parameters:
        s - The string to convert into bytes.
    • Method Detail

      • add

        public void add​(String s)
        Adds a string to the stream. This will update all of the necessary variables in order to make reading from this stream possible again.
        Parameters:
        s - The string to add.
        See Also:
        Arrays.copyOf(byte[], int)