org.w3c.util
Class CountOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.w3c.util.CountOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class CountOutputStream
extends java.io.OutputStream

This class can be used to count number of bytes emitted to a stream. The stream will actually throw the data away. It's main function is to count the number of bytes emitted to a stream before actually emitting the bytes (that's not really efficient, but works enough).


Field Summary
protected  int count
           
 
Constructor Summary
CountOutputStream()
          Create a new instance of that class.
 
Method Summary
 void close()
          Close that count stream.
 void flush()
          Flush that count stream.
 int getCount()
          Get the current number of bytes emitted to that stream.
 void write(byte[] b)
          Write an array of bytes to that stream.
 void write(byte[] b, int off, int len)
          Write part of an array of bytes to that stream.
 void write(int b)
          Write a single byte to that stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

protected int count
Constructor Detail

CountOutputStream

public CountOutputStream()
Create a new instance of that class.

Method Detail

getCount

public int getCount()
Get the current number of bytes emitted to that stream.

Returns:
The current count value.

close

public void close()
Close that count stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream

flush

public void flush()
Flush that count stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream

write

public void write(byte[] b)
Write an array of bytes to that stream.

Overrides:
write in class java.io.OutputStream

write

public void write(byte[] b,
                  int off,
                  int len)
Write part of an array of bytes to that stream.

Overrides:
write in class java.io.OutputStream

write

public void write(int b)
Write a single byte to that stream.

Specified by:
write in class java.io.OutputStream