Package com.coswald.jtalker
Class TextInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.ByteArrayInputStream
-
- com.coswald.jtalker.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 anInputStream
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
-
-
Field Summary
-
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
-
-
Constructor Summary
Constructors Constructor Description TextInputStream(byte[] buf)
Creates aTextInputStream
so that it usesbuf
as its buffer array.TextInputStream(byte[] buf, int offset, int length)
Creates aTextInputStream
that usesbuf
as its buffer array.TextInputStream(String s)
Creates a stream with the given String as the starting bytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String s)
Adds a string to the stream.-
Methods inherited from class java.io.ByteArrayInputStream
available, close, mark, markSupported, read, read, readAllBytes, readNBytes, reset, skip, transferTo
-
Methods inherited from class java.io.InputStream
nullInputStream, read, readNBytes
-
-
-
-
Constructor Detail
-
TextInputStream
public TextInputStream(byte[] buf)
Creates aTextInputStream
so that it usesbuf
as its buffer array. The buffer array is not copied. The initial value ofpos
is 0 and the initial value ofcount
is the length ofbuf
.
-
TextInputStream
public TextInputStream(byte[] buf, int offset, int length)
Creates aTextInputStream
that usesbuf
as its buffer array. The initial value ofpos
isoffset
and the initial value ofcount
is the minimum ofoffset + length
andbuf.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)
-
-