Class FSDataOutputStream

All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable, Abortable, CanSetDropBehind, org.apache.hadoop.fs.statistics.IOStatisticsSource, StreamCapabilities, Syncable
Direct Known Subclasses:
HdfsDataOutputStream

@Public @Stable public class FSDataOutputStream extends DataOutputStream implements Syncable, CanSetDropBehind, StreamCapabilities, org.apache.hadoop.fs.statistics.IOStatisticsSource, Abortable
Utility that wraps a OutputStream in a DataOutputStream.
  • Constructor Details

    • FSDataOutputStream

      public FSDataOutputStream(OutputStream out, org.apache.hadoop.fs.FileSystem.Statistics stats)
    • FSDataOutputStream

      public FSDataOutputStream(OutputStream out, org.apache.hadoop.fs.FileSystem.Statistics stats, long startPosition)
  • Method Details

    • getPos

      public long getPos()
      Get the current position in the output stream.
      Returns:
      the current position in the output stream
    • close

      public void close() throws IOException
      Close the underlying output stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterOutputStream
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getWrappedStream

      @LimitedPrivate("HDFS") public OutputStream getWrappedStream()
      Get a reference to the wrapped output stream.
      Returns:
      the underlying output stream
    • hasCapability

      public boolean hasCapability(String capability)
      Description copied from interface: StreamCapabilities
      Query the stream for a specific capability.
      Specified by:
      hasCapability in interface StreamCapabilities
      Parameters:
      capability - string to query the stream support for.
      Returns:
      True if the stream supports capability.
    • hflush

      public void hflush() throws IOException
      Description copied from interface: Syncable
      Flush out the data in client's user buffer. After the return of this call, new readers will see the data.
      Specified by:
      hflush in interface Syncable
      Throws:
      IOException - if any error occurs
    • hsync

      public void hsync() throws IOException
      Description copied from interface: Syncable
      Similar to posix fsync, flush out the data in client's user buffer all the way to the disk device (but the disk may have it in its cache).
      Specified by:
      hsync in interface Syncable
      Throws:
      IOException - if error occurs
    • setDropBehind

      public void setDropBehind(Boolean dropBehind) throws IOException
      Description copied from interface: CanSetDropBehind
      Configure whether the stream should drop the cache.
      Specified by:
      setDropBehind in interface CanSetDropBehind
      Parameters:
      dropBehind - Whether to drop the cache. null means to use the default value.
      Throws:
      IOException - If there was an error changing the dropBehind setting. UnsupportedOperationException If this stream doesn't support setting the drop-behind.
    • getIOStatistics

      public IOStatistics getIOStatistics()
      Get the IO Statistics of the nested stream, falling back to empty statistics if the stream does not implement the interface IOStatisticsSource.
      Specified by:
      getIOStatistics in interface org.apache.hadoop.fs.statistics.IOStatisticsSource
      Returns:
      an IOStatistics instance.
    • abort

      public org.apache.hadoop.fs.Abortable.AbortableResult abort()
      Invoke abort() on the wrapped stream if it is Abortable, otherwise raise an UnsupportedOperationException.
      Specified by:
      abort in interface Abortable
      Returns:
      the result.
      Throws:
      UnsupportedOperationException - if not available.