|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream java.io.ByteArrayOutputStream ca.idms.io.TraceBufferOutputStream
public class TraceBufferOutputStream
A TraceBufferOutputStream extends ByteArrayOutputStream to provide tracing and buffering of an underlying OutputStream.
Data written to the stream is collected in a buffer, which grows as needed. When the flush method is called, the contents of the buffer are displayed in the trace stream, if enabled, and written to the output stream. The ByteArrayInputStream methods are used to write data to 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
,
ByteArrayOutputStream
Field Summary | |
---|---|
protected java.io.OutputStream |
out
The actual output stream. |
protected TraceObject |
trace
The trace control object. |
Fields inherited from class java.io.ByteArrayOutputStream |
---|
buf, count |
Constructor Summary | |
---|---|
TraceBufferOutputStream(TraceObject trace,
int len)
Creates a buffered trace stream with no underlying output stream. |
|
TraceBufferOutputStream(TraceObject trace,
java.io.OutputStream out)
Creates a buffered trace stream with a default buffer size. |
|
TraceBufferOutputStream(TraceObject trace,
java.io.OutputStream out,
int len)
Creates a buffered trace stream to write data to the specified underlying output stream. |
Method Summary | |
---|---|
void |
flush()
Flushes this output stream and forces any buffered output bytes to be written out to the stream. |
byte[] |
getBuffer()
Gets a reference to the buffer. |
int |
getCount()
Gets the number of valid bytes in the buffer. |
void |
setBuffer(byte[] buf,
int len)
Sets the buffer. |
void |
setCount(int len)
Set the number of valid bytes in the buffer. |
void |
setSize(int len)
Sets the size of the buffer. |
void |
snap(boolean f)
Displays the contents of this buffer if tracing is enabled. |
Methods inherited from class java.io.ByteArrayOutputStream |
---|
close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo |
Methods inherited from class java.io.OutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected TraceObject trace
protected java.io.OutputStream out
Constructor Detail |
---|
public TraceBufferOutputStream(TraceObject trace, java.io.OutputStream out, int len)
trace
- the trace control objectout
- the underlying output stream.len
- the initial size of the buffer.public TraceBufferOutputStream(TraceObject trace, java.io.OutputStream out)
trace
- the trace control objectout
- the underlying output stream.public TraceBufferOutputStream(TraceObject trace, int len)
trace
- the trace control objectlen
- the initial size of the buffer.Method Detail |
---|
public void setSize(int len)
len
- new buffer size.public byte[] getBuffer()
Note that subsequent writes to this stream can change the contents of the buffer, and changing the contents of the buffer can corrupt the state of the stream.
public void setBuffer(byte[] buf, int len)
buf
- the new buffer contentslen
- the length used in the arraypublic int getCount()
public void setCount(int len)
len
- new count, ignored if out of rangegetCount()
public void snap(boolean f)
TraceObject
public void flush() throws java.io.IOException
The buffer is displayed in the log if tracing bytes is enabled. This method will throw a NullPointerException if there is no underlying output stream.
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
- if an I/O error occurs.TraceObject
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |