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 InputStreamprivate InheritableThreadLocalThe InputStreams for the various threads -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()(package private) InputStreamReturns this thread's InputStream(package private) voidinit(InputStream streamForCurrentThread) Sets the InputStream for the current threadvoidmark(int readlimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()longskip(long n)
-
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:
availablein classInputStream- Throws:
IOException- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- See Also:
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream- See Also:
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream- See Also:
-
read
- Specified by:
readin classInputStream- Throws:
IOException- See Also:
-
read
- Overrides:
readin classInputStream- Throws:
IOException- See Also:
-
read
- Overrides:
readin classInputStream- Throws:
IOException- See Also:
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException- See Also:
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException- See Also:
-