Package com.martiansoftware.nailgun
Class ThreadLocalInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.martiansoftware.nailgun.ThreadLocalInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
class ThreadLocalInputStream extends java.io.InputStream
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
Fields Modifier and Type Field Description private java.io.InputStream
defaultInputStream
private java.lang.InheritableThreadLocal
streams
The InputStreams for the various threads
-
Constructor Summary
Constructors Constructor Description ThreadLocalInputStream(java.io.InputStream defaultInputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
(package private) java.io.InputStream
getInputStream()
Returns this thread's InputStream(package private) void
init(java.io.InputStream streamForCurrentThread)
Sets the InputStream for the current threadvoid
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
void
reset()
long
skip(long n)
-
-
-
Method Detail
-
init
void init(java.io.InputStream streamForCurrentThread)
Sets the InputStream for the current thread- Parameters:
streamForCurrentThread
- the InputStream for the current thread
-
getInputStream
java.io.InputStream getInputStream()
Returns this thread's InputStream- Returns:
- this thread's InputStream
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.available()
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.close()
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classjava.io.InputStream
- See Also:
InputStream.mark(int)
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.InputStream
- See Also:
InputStream.markSupported()
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.read()
-
read
public int read(byte[] b) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.read(byte[])
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.read(byte[],int,int)
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.reset()
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
- See Also:
InputStream.skip(long)
-
-