Class CountOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public final class CountOutputStream
    extends java.io.OutputStream
    An OutputStream that counts the written bytes.
    Since:
    08.11.2006
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int bytesWritten
      the byte counter
      private java.io.OutputStream out
      the decorated output stream
    • Constructor Summary

      Constructors 
      Constructor Description
      CountOutputStream​(java.io.OutputStream out)
      Constructor with providing the output stream to decorate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getBytesWritten()  
      void write​(byte[] buf)
      Counts the written bytes.
      void write​(byte[] buf, int off, int len)
      Counts the written bytes.
      void write​(int b)
      Counts the written bytes.
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • out

        private final java.io.OutputStream out
        the decorated output stream
      • bytesWritten

        private int bytesWritten
        the byte counter
    • Constructor Detail

      • CountOutputStream

        CountOutputStream​(java.io.OutputStream out)
        Constructor with providing the output stream to decorate.
        Parameters:
        out - an OutputStream
    • Method Detail

      • write

        public void write​(byte[] buf,
                          int off,
                          int len)
                   throws java.io.IOException
        Counts the written bytes.
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
        See Also:
        OutputStream.write(byte[], int, int)
      • write

        public void write​(byte[] buf)
                   throws java.io.IOException
        Counts the written bytes.
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
        See Also:
        OutputStream.write(byte[])
      • write

        public void write​(int b)
                   throws java.io.IOException
        Counts the written bytes.
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
        See Also:
        OutputStream.write(int)
      • getBytesWritten

        public int getBytesWritten()
        Returns:
        the bytesWritten