Class SequentialWriter

All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable, DataOutputPlus, Transactional
Direct Known Subclasses:
ChecksummedSequentialWriter, CompressedSequentialWriter

public class SequentialWriter extends BufferedDataOutputStreamPlus implements Transactional
Adds buffering, mark, and fsyncing to OutputStream. We always fsync on close; we may also fsync incrementally if Config.trickle_fsync is enabled.
  • Field Details

    • bufferOffset

      protected long bufferOffset
    • fchannel

      protected final FileChannel fchannel
    • option

      protected final SequentialWriterOption option
    • lastFlushOffset

      protected long lastFlushOffset
    • runPostFlush

      protected LongConsumer runPostFlush
  • Constructor Details

    • SequentialWriter

      public SequentialWriter(File file)
      Create heap-based, non-compressed SequenialWriter with default buffer size(64k).
      Parameters:
      file - File to write
    • SequentialWriter

      public SequentialWriter(File file, SequentialWriterOption option)
      Create SequentialWriter for given file with specific writer option.
      Parameters:
      file - File to write
      option - Writer option
    • SequentialWriter

      public SequentialWriter(File file, SequentialWriterOption option, boolean strictFlushing)
      Create SequentialWriter for given file with specific writer option.
      Parameters:
      file -
      option -
      strictFlushing -
    • SequentialWriter

      protected SequentialWriter(File file, ByteBuffer buffer, SequentialWriterOption option, boolean strictFlushing)
  • Method Details

    • skipBytes

      public void skipBytes(long numBytes) throws IOException
      Throws:
      IOException
    • sync

      public void sync()
      Synchronize file contents with disk.
    • syncDataOnlyInternal

      protected void syncDataOnlyInternal()
    • syncInternal

      protected void syncInternal()
    • doFlush

      protected void doFlush(int count)
      Overrides:
      doFlush in class BufferedDataOutputStreamPlus
    • setPostFlushListener

      public void setPostFlushListener(LongConsumer runPostFlush)
    • flushData

      protected void flushData()
      Override this method instead of overriding flush()
      Throws:
      FSWriteError - on any I/O error.
    • hasPosition

      public boolean hasPosition()
      Description copied from interface: DataOutputPlus
      If the implementation supports providing a position, this method returns true, otherwise false.
      Specified by:
      hasPosition in interface DataOutputPlus
    • position

      public long position()
      Description copied from interface: DataOutputPlus
      Returns the current position of the underlying target like a file-pointer or the position withing a buffer. Not every implementation may support this functionality. Whether or not this functionality is supported can be checked via the DataOutputPlus.hasPosition().
      Specified by:
      position in interface DataOutputPlus
    • maxBytesInPage

      public int maxBytesInPage()
      Description copied from interface: DataOutputPlus
      Returns the number of bytes that a page can take at maximum.
      Specified by:
      maxBytesInPage in interface DataOutputPlus
    • padToPageBoundary

      public void padToPageBoundary() throws IOException
      Description copied from interface: DataOutputPlus
      Pad this with zeroes until the next page boundary. If the destination position is already at a page boundary, do not do anything.
      Specified by:
      padToPageBoundary in interface DataOutputPlus
      Throws:
      IOException
    • bytesLeftInPage

      public int bytesLeftInPage()
      Description copied from interface: DataOutputPlus
      Returns how many bytes are left in the page.
      Specified by:
      bytesLeftInPage in interface DataOutputPlus
    • paddedPosition

      public long paddedPosition()
      Description copied from interface: DataOutputPlus
      Returns the next padded position. This is either the current position (if already padded), or the start of next page.
      Specified by:
      paddedPosition in interface DataOutputPlus
    • getOnDiskFilePointer

      public long getOnDiskFilePointer()
      Returns the current file pointer of the underlying on-disk file. Note that since write works by buffering data, the value of this will increase by buffer size and not every write to the writer will modify this value. Furthermore, for compressed files, this value refers to compressed data, while the writer getFilePointer() refers to uncompressedFile
      Returns:
      the current file pointer
    • getEstimatedOnDiskBytesWritten

      public long getEstimatedOnDiskBytesWritten()
    • length

      public long length()
    • getPath

      public String getPath()
    • getFile

      public File getFile()
    • resetBuffer

      protected void resetBuffer()
    • current

      protected long current()
    • mark

      public DataPosition mark()
    • resetAndTruncate

      public void resetAndTruncate(DataPosition mark)
      Drops all buffered data that's past the limits of our new file mark + buffer capacity, or syncs and truncates the underlying file to the marked position
    • getLastFlushOffset

      public long getLastFlushOffset()
    • truncate

      public void truncate(long toSize)
    • isOpen

      public boolean isOpen()
    • prepareToCommit

      public final void prepareToCommit()
      Specified by:
      prepareToCommit in interface Transactional
    • commit

      public final Throwable commit(Throwable accumulate)
      Specified by:
      commit in interface Transactional
    • abort

      public final Throwable abort(Throwable accumulate)
      Specified by:
      abort in interface Transactional
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Transactional
      Overrides:
      close in class BufferedDataOutputStreamPlus
    • writeDirectlyToChannel

      public int writeDirectlyToChannel(ByteBuffer buf) throws IOException
      Throws:
      IOException
    • finish

      public final void finish()
    • txnProxy