public class LoggerInputStream
extends java.io.InputStream
An InputStream designed to record data passing through the stream after a call to record() is made. After record() is called, the results from every read will be stored in an * internal buffer. The contents of the buffer can be retrieved by getRecordedData(); to stop recording and clear the internal buffer, call stopRecording().
Note: calls to mark() and reset() are merely passed through to the inner stream; if recording is active, the buffer won't be backtracked by reset().
Modifier and Type | Field and Description |
---|---|
private java.io.ByteArrayOutputStream |
baos |
private java.io.ByteArrayInputStream |
innerStream |
private boolean |
recording |
Constructor and Description |
---|
LoggerInputStream(byte[] buffer) |
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
byte[] |
getRecordedData()
Returns the data recorded so far; if recording is not active, an empty buffer
is returned.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
void |
record()
If not currently recording, start recording.
|
void |
reset() |
long |
skip(long n) |
void |
stopRecording()
Stops recording and clears the internal buffer.
|
private java.io.ByteArrayInputStream innerStream
private java.io.ByteArrayOutputStream baos
private boolean recording
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
public void mark(int readlimit)
mark
in class java.io.InputStream
public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
public boolean markSupported()
markSupported
in class java.io.InputStream
public void record()
public void stopRecording() throws java.io.IOException
java.io.IOException
- if recording is not currently activepublic byte[] getRecordedData()