|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.ByteArrayInputStream ca.idms.io.TraceBufferInputStream
public class TraceBufferInputStream
A TraceBufferInputStream extends ByteArrayInputStream to provide tracing and buffering of an underlying InputStream.
When the read(int) method is called, int bytes of data are read from the input stream into a buffer, which is allocated as needed, and the contents of the buffer are displayed in the trace stream, if enabled. The ByteArrayInputStream methods are used to read data from the buffer.
This class also provides methods to optimize buffering by explicitly setting the size buffer and allowing access to the buffer without copying it.
TraceObject
,
ByteArrayInputStream
Field Summary | |
---|---|
protected java.io.InputStream |
in
The underlying input stream. |
protected TraceObject |
trace
The trace control object. |
Fields inherited from class java.io.ByteArrayInputStream |
---|
buf, count, mark, pos |
Constructor Summary | |
---|---|
TraceBufferInputStream(TraceObject trace,
byte[] buf)
Creates a buffered trace stream from a byte array. |
|
TraceBufferInputStream(TraceObject trace,
byte[] buf,
int off,
int len)
Creates a buffered trace stream from a byte array. |
|
TraceBufferInputStream(TraceObject trace,
java.io.InputStream in)
Creates a buffered trace stream with a default buffer size. |
|
TraceBufferInputStream(TraceObject trace,
java.io.InputStream in,
int len)
Creates a buffered trace stream to read data from the specified underlying input stream. |
Method Summary | |
---|---|
void |
close()
Closes the ByteArrayInputStream and releases the buffer. |
byte[] |
getBuffer()
Gets the buffer. |
int |
getCount()
Gets the number of valid bytes in the buffer. |
int |
getPosition()
Gets the index of the next character to be read. |
int |
read(int len)
Reads the next buffer of data from the input stream. |
void |
setSize(int len)
Sets the size of the buffer. |
long |
skip(long n)
Skips over n bytes of data in the buffer. |
void |
snap()
Displays the contents of this buffer if tracing is enabled. |
Methods inherited from class java.io.ByteArrayInputStream |
---|
available, mark, markSupported, read, read, reset |
Methods inherited from class java.io.InputStream |
---|
read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected TraceObject trace
protected java.io.InputStream in
Constructor Detail |
---|
public TraceBufferInputStream(TraceObject trace, java.io.InputStream in, int len)
trace
- the trace control objectin
- the underlying input stream.len
- the initial size of the buffer.public TraceBufferInputStream(TraceObject trace, java.io.InputStream in)
trace
- the trace control objectin
- the underlying input stream.public TraceBufferInputStream(TraceObject trace, byte[] buf)
trace
- the trace control objectbuf
- the byte array.public TraceBufferInputStream(TraceObject trace, byte[] buf, int off, int len)
trace
- the trace control objectbuf
- the byte array.off
- offset into the byte array.len
- length of sub array.Method Detail |
---|
public void setSize(int len)
public byte[] getBuffer()
public int getCount()
public int getPosition()
public void snap()
TraceObject
public int read(int len) throws java.io.IOException
len
- the number of bytes to read.
java.io.EOFException
- if end of file on input.
java.io.IOException
- if an I/O error occurs.public long skip(long n)
This method also avoids what appears to be bug in DataInputStream, which enters an infinite loop when n is greater than the number of bytes available. In that case this pretends it skipped the requested number of bytes.
skip
in class java.io.ByteArrayInputStream
n
- the number of bytes to be skipped.
public void close() throws java.io.IOException
Note that the underlying input stream is not closed.
close
in interface java.io.Closeable
close
in class java.io.ByteArrayInputStream
java.io.IOException
- if an I/O error occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |