org.opengts.util
Class CachedLogOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by org.opengts.util.CachedLogOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class CachedLogOutputStream
extends java.io.ByteArrayOutputStream

Cached Logging text OutputStream


Field Summary
static int DEFAULT_MAXIMUM_LENGTH
           
static int DEFAULT_MINIMUM_LENGTH
           
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
CachedLogOutputStream()
           
CachedLogOutputStream(int minSize, int maxSize)
           
 
Method Summary
protected  java.lang.String _readLine(boolean removeLine)
          Reads, and optionally removes, a line of text from the byte array.
 long getDiscardID()
          Returns the discard-ID.
static void main(java.lang.String[] argv)
           
 java.lang.String peekLine()
          Reads a line of text from the byte array (line is not removed)
 java.lang.String readLine()
          Reads and removes a line of text from the byte array.
 void reset()
          Clears/reset the logging text in this cache.
 int size()
          Gets the current size of the buffer
 void write(byte[] b, int ofs, int len)
          Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
 void write(int b)
          Writes the specified byte to this byte array output stream.
 void write(java.lang.String s)
          Writes the specified String to this byte array output stream.
 void writeln(java.lang.String s)
          Writes the specified String to this byte array output stream.
 
Methods inherited from class java.io.ByteArrayOutputStream
close, toByteArray, toString, toString, toString, writeTo
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MINIMUM_LENGTH

public static final int DEFAULT_MINIMUM_LENGTH
See Also:
Constant Field Values

DEFAULT_MAXIMUM_LENGTH

public static final int DEFAULT_MAXIMUM_LENGTH
See Also:
Constant Field Values
Constructor Detail

CachedLogOutputStream

public CachedLogOutputStream()

CachedLogOutputStream

public CachedLogOutputStream(int minSize,
                             int maxSize)
Method Detail

reset

public void reset()
Clears/reset the logging text in this cache.

Overrides:
reset in class java.io.ByteArrayOutputStream

size

public int size()
Gets the current size of the buffer

Overrides:
size in class java.io.ByteArrayOutputStream
Returns:
The current size of the buffer

getDiscardID

public long getDiscardID()
Returns the discard-ID. The discard-ID is incremented each time any logging text is discarded from the cache. During the retrieval of logging data (see readLine), if this discard-ID changes, it means that there was some logging data lost due to the buffer having been filled, and old logging data discarded.


write

public void write(int b)
Writes the specified byte to this byte array output stream.

Overrides:
write in class java.io.ByteArrayOutputStream
Parameters:
b - the byte to be written.

write

public void write(byte[] b,
                  int ofs,
                  int len)
Writes len bytes from the specified byte array starting at offset off to this byte array output stream.

Overrides:
write in class java.io.ByteArrayOutputStream
Parameters:
b - the data.
ofs - the start offset in the data.
len - the number of bytes to write.

write

public void write(java.lang.String s)
Writes the specified String to this byte array output stream.

Parameters:
s - the String to be written.

writeln

public void writeln(java.lang.String s)
Writes the specified String to this byte array output stream.

Parameters:
s - the String to be written.

_readLine

protected java.lang.String _readLine(boolean removeLine)
Reads, and optionally removes, a line of text from the byte array.

Parameters:
removeLine - True to remove the line which has been read.
Returns:
The line of text read, or null if there is no text in the byte-array

readLine

public java.lang.String readLine()
Reads and removes a line of text from the byte array.

Returns:
The line of text read, or null if there is no text in the byte-array

peekLine

public java.lang.String peekLine()
Reads a line of text from the byte array (line is not removed)

Returns:
The line of text read, or null if there is no text in the byte-array

main

public static void main(java.lang.String[] argv)