Package com.martiansoftware.nailgun
Class ThreadLocalInputStream
java.lang.Object
java.io.InputStream
com.martiansoftware.nailgun.ThreadLocalInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
The class name is pretty descriptive. This creates an InputStream
much like a FilterInputStream, but with the wrapped InputStream
being local to the current Thread. By setting System.in to a
ThreadLocalInputStream, different Threads can read from different
InputStreams simply by using System.in. Of course, the init()
method must be called by the Thread that wishes to use the
wrapped stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate InputStream
private InheritableThreadLocal
The InputStreams for the various threads -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
(package private) InputStream
Returns this thread's InputStream(package private) void
init
(InputStream streamForCurrentThread) Sets the InputStream for the current threadvoid
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) void
reset()
long
skip
(long n) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
streams
The InputStreams for the various threads -
defaultInputStream
-
-
Constructor Details
-
ThreadLocalInputStream
ThreadLocalInputStream(InputStream defaultInputStream) - Parameters:
defaultInputStream
- the InputStream that will be used if the current thread has not called init()
-
-
Method Details
-
init
Sets the InputStream for the current thread- Parameters:
streamForCurrentThread
- the InputStream for the current thread
-
getInputStream
InputStream getInputStream()Returns this thread's InputStream- Returns:
- this thread's InputStream
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
- See Also:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- See Also:
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
- See Also:
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
- See Also:
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
- See Also:
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
- See Also:
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
- See Also:
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
- See Also:
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
- See Also:
-