All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class CountingOutputStreamextends FilterOutputStream
OutputStream that counts bytes written.
  • Field Details

    • count

      private long count
      Bytes written so far.
  • Constructor Details

    • CountingOutputStream

      public CountingOutputStream(OutputStream out)
      Create a CountingOutputStream wrapping the given output stream.
      Parameters:
      out - the underlying output stream
  • Method Details

    • getWritten

      public long getWritten()
      Get the total number of bytes written so far.
      Returns:
      total bytes written
    • write

      public void write(int val) throws IOException
      Write a single byte and count it.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      val - the byte to write
      Throws:
      IOException - on I/O error
    • write

      public void write(byte[] src, int off, int len) throws IOException
      Write bytes from a buffer and count them.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      src - the buffer to write from
      off - the start offset in the buffer
      len - the number of bytes to write
      Throws:
      IOException - on I/O error