Class MeteredStream

java.lang.Object
java.io.OutputStream
org.forgerock.audit.events.handlers.writers.MeteredStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class MeteredStream extends OutputStream
A metered stream is a subclass of OutputStream that (a) forwards all its output to a target stream (b) keeps track of how many bytes have been written.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MeteredStream(OutputStream out, long written)
    Create the stream wrapped around the specified output stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the output stream which closes the target output stream.
    void
    Flush the output stream which flushes the target output stream.
    long
    Returns the number of bytes written in this stream.
    void
    write(byte[] buff)
    Write the specified buffer to the stream.
    void
    write(byte[] buff, int off, int len)
    Write the specified buffer to the stream.
    void
    write(int b)
    Write the specified byte to the stream.

    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
  • Constructor Details

    • MeteredStream

      public MeteredStream(OutputStream out, long written)
      Create the stream wrapped around the specified output stream.
      Parameters:
      out - The target output stream to keep track of.
      written - The number of bytes written to the stream.
  • Method Details

    • write

      public void write(int b) throws IOException
      Write the specified byte to the stream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - The value to be written to the stream.
      Throws:
      IOException - if the write failed.
    • write

      public void write(byte[] buff) throws IOException
      Write the specified buffer to the stream.
      Overrides:
      write in class OutputStream
      Parameters:
      buff - The value to be written to the stream.
      Throws:
      IOException - if the write failed.
    • write

      public void write(byte[] buff, int off, int len) throws IOException
      Write the specified buffer to the stream.
      Overrides:
      write in class OutputStream
      Parameters:
      buff - The value to be written to the stream.
      off - The offset to write from.
      len - The length of the buffer to write.
      Throws:
      IOException - if the write failed.
    • flush

      public void flush() throws IOException
      Flush the output stream which flushes the target output stream.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if the flush failed.
    • close

      public void close() throws IOException
      Close the output stream which closes the target output stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException - if the close failed.
    • getBytesWritten

      public long getBytesWritten()
      Returns the number of bytes written in this stream.
      Returns:
      the number of bytes