Class CountingOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.ka2ddo.yaac.io.CountingOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class CountingOutputStream extends FilterOutputStream
This class is a FilterOutputStream that counts the number of bytes written to the lower-level OutputStream.
Author:
Andrew Pavlin, KA2DDO
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    long
    Number of bytes forwarded to the encapsulated OutputStream.

    Fields inherited from class java.io.FilterOutputStream

    out
  • Constructor Summary

    Constructors
    Constructor
    Description
    Wrap a stream that counts the number of bytes written around another OutputStream,
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Get the number of bytes passed through this stream (so far).
    void
    write(byte[] b)
    Writes b.length bytes to this output stream.
    void
    write(byte[] b, int off, int len)
    Writes len bytes from the specified byte array starting at offset off to this output stream.
    void
    write(int b)
    Writes the specified byte to this output stream.

    Methods inherited from class java.io.FilterOutputStream

    close, flush

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • count

      public long count
      Number of bytes forwarded to the encapsulated OutputStream.
  • Constructor Details

    • CountingOutputStream

      public CountingOutputStream(OutputStream out)
      Wrap a stream that counts the number of bytes written around another OutputStream,
      Parameters:
      out - OutputStream to received forwarded bytes
  • Method Details

    • write

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

      The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b).

      Implements the abstract write method of OutputStream.

      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - the byte.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes to this output stream.

      The write method of FilterOutputStream calls its write method of three arguments with the arguments b, 0, and b.length.

      Note that this method does not call the one-argument write method of its underlying stream with the single argument b.

      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - the data to be written.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • write

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

      The write method of FilterOutputStream calls the write method of one argument on each byte to output.

      Note that this method does not call the write method of its underlying input stream with the same arguments. Subclasses of FilterOutputStream should provide a more efficient implementation of this method.

      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - the data.
      off - the start offset in the data.
      len - the number of bytes to write.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • getByteCount

      public long getByteCount()
      Get the number of bytes passed through this stream (so far).
      Returns:
      the number of written bytes so far.