Class BufferedIOStatisticsOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.BufferedOutputStream
org.apache.hadoop.fs.statistics.BufferedIOStatisticsOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, IOStatisticsSource, StreamCapabilities, Syncable

public class BufferedIOStatisticsOutputStream extends BufferedOutputStream implements IOStatisticsSource, Syncable, StreamCapabilities
An extension of BufferedOutputStream which implements IOStatisticsSource and forwards requests for the IOStatistics to the wrapped stream. This should be used when any output stream needs buffering while allowing the inner stream to be a source of statistics. It also implements StreamCapabilities and Syncable and forwards to to the inner stream, if possible.
  • Constructor Details

    • BufferedIOStatisticsOutputStream

      public BufferedIOStatisticsOutputStream(OutputStream out, boolean downgradeSyncable)
      Construct with default buffer size.
      Parameters:
      out - output stream to buffer
      downgradeSyncable - should Syncable calls downgrade?
    • BufferedIOStatisticsOutputStream

      public BufferedIOStatisticsOutputStream(OutputStream out, int size, boolean downgradeSyncable)
      Construct with custom buffer size.
      Parameters:
      out - output stream to buffer
      size - buffer.
      downgradeSyncable - should Syncable calls downgrade?
  • Method Details

    • getIOStatistics

      public IOStatistics getIOStatistics()
      Ask the inner stream for their IOStatistics.
      Specified by:
      getIOStatistics in interface IOStatisticsSource
      Returns:
      any IOStatistics offered by the inner stream.
    • hasCapability

      public boolean hasCapability(String capability)
      If the inner stream supports StreamCapabilities, forward the probe to it. Otherwise: return false.
      Specified by:
      hasCapability in interface StreamCapabilities
      Parameters:
      capability - string to query the stream support for.
      Returns:
      true if a capability is known to be supported.
    • hflush

      public void hflush() throws IOException
      If the inner stream is Syncable, flush the buffer and then invoke the inner stream's hflush() operation. Otherwise: throw an exception, unless the stream was constructed with downgradeSyncable set to true, in which case the stream is just flushed.
      Specified by:
      hflush in interface Syncable
      Throws:
      IOException - IO Problem
      UnsupportedOperationException - if the inner class is not syncable
    • hsync

      public void hsync() throws IOException
      If the inner stream is Syncable, flush the buffer and then invoke the inner stream's hsync() operation. Otherwise: throw an exception, unless the stream was constructed with downgradeSyncable set to true, in which case the stream is just flushed.
      Specified by:
      hsync in interface Syncable
      Throws:
      IOException - IO Problem
      UnsupportedOperationException - if the inner class is not syncable