Stellent
HowToComponents
JavaDoc

intradoc.common
Class TruncatedOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--intradoc.common.TruncatedOutputStream

public class TruncatedOutputStream
extends java.io.OutputStream

Specialized output stream used to retain a fixed number of lines in a buffer.


Field Summary
protected  byte[] m_buffer
          The buffer where data is stored.
protected  int m_count
          The number of valid bytes in the buffer.
protected  int m_lineCount
          The number of lines in the buffer
protected  int m_maxLineCount
          The fixed line length of the buffer.
 
Constructor Summary
TruncatedOutputStream()
          Creates a new TruncatedOutputStream.
TruncatedOutputStream(int lines)
          Creates a new TruncatedOutputStream, with a fixed length of the specified size, in bytes.
 
Method Summary
protected  void countLines(byte[] b, int off, int len)
          Returns the number of lines in the data buffer.
protected  void removeExcessLines()
          Removes characters from the beginning of the buffer to the n-th newline character, determined by the number passed.
 void reset()
          Resets the count field of this byte array output stream to zero, so that all currently accumulated output in the ouput stream is discarded.
 boolean setMaxLines(int lines)
          Sets the maxLineCount to the number of lines passed.
 int size()
          Returns the current size of the buffer.
 java.lang.String toString()
          Converts the buffer's contents into a string.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array, starting at offset off, to the end of this TruncatedOutputStream.
 void write(int b)
          Writes the specified byte to this TruncatedOutputStream.
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_buffer

protected byte[] m_buffer
The buffer where data is stored.


m_count

protected int m_count
The number of valid bytes in the buffer.


m_lineCount

protected int m_lineCount
The number of lines in the buffer


m_maxLineCount

protected int m_maxLineCount
The fixed line length of the buffer.

Constructor Detail

TruncatedOutputStream

public TruncatedOutputStream()
Creates a new TruncatedOutputStream.


TruncatedOutputStream

public TruncatedOutputStream(int lines)
Creates a new TruncatedOutputStream, with a fixed length of the specified size, in bytes. The smallest stream that can be allocated has at least 1 line.

Parameters:
lines - The maximum number of lines in the buffer.
Method Detail

setMaxLines

public boolean setMaxLines(int lines)
Sets the maxLineCount to the number of lines passed.

Parameters:
lines - The maximum number of lines in the buffer.

write

public void write(int b)
Writes the specified byte to this TruncatedOutputStream. If the new count is greater than the size, the first byte is discarded.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte to be written.

write

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

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

countLines

protected void countLines(byte[] b,
                          int off,
                          int len)
Returns the number of lines in the data buffer.

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to check.

removeExcessLines

protected void removeExcessLines()
Removes characters from the beginning of the buffer to the n-th newline character, determined by the number passed.


size

public int size()
Returns the current size of the buffer.


toString

public java.lang.String toString()
Converts the buffer's contents into a string.

Overrides:
toString in class java.lang.Object

reset

public void reset()
Resets the count field of this byte array output stream to zero, so that all currently accumulated output in the ouput stream is discarded.



(c) 1996-2005  All rights reserved.  Stellent, Inc.