org.apache.cassandra.io.util

## Class SequentialWriter

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.cassandra.io.util.DataOutputStreamPlus
    - - org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
      - - org.apache.cassandra.io.util.SequentialWriter

All Implemented Interfaces:
  java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.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.

### Nested Class Summary

Nested Classes
`protected static class` `SequentialWriter.BufferedFileWriterMark` Class to hold a mark to the position of the file
`protected class` `SequentialWriter.TransactionalProxy`

### Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional

`Transactional.AbstractTransactional`

### Field Summary

Fields
`protected long` `bufferOffset`
`protected java.nio.channels.FileChannel` `fchannel`
`protected long` `lastFlushOffset`
`protected java.lang.Runnable` `runPostFlush`

### Fields inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus

`buffer, strictFlushing`

### Fields inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus

`channel`

### Constructor Summary

Constructors
Constructor and Description
`SequentialWriter(java.io.File file)` Create heap-based, non-compressed SequenialWriter with default buffer size(64k).
`SequentialWriter(java.io.File file, SequentialWriterOption option)` Create SequentialWriter for given file with specific writer option.

### Method Summary

All Methods Instance Methods Concrete Methods
`java.lang.Throwable` `abort(java.lang.Throwable accumulate)`
`void` `close()`
`java.lang.Throwable` `commit(java.lang.Throwable accumulate)`
`protected long` `current()`
`protected void` `doFlush(int count)`
`void` `finish()`
`protected void` `flushData()` Override this method instead of overriding flush()
`long` `getEstimatedOnDiskBytesWritten()`
`long` `getLastFlushOffset()`
`long` `getOnDiskFilePointer()` Returns the current file pointer of the underlying on-disk file.
`java.lang.String` `getPath()`
`boolean` `hasPosition()` If the implementation supports providing a position, this method returns `true`, otherwise `false`.
`boolean` `isOpen()`
`long` `length()`
`DataPosition` `mark()`
`long` `position()` Returns the current position of the underlying target like a file-pointer or the position withing a buffer.
`void` `prepareToCommit()`
`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
`protected void` `resetBuffer()`
`void` `setPostFlushListener(java.lang.Runnable runPostFlush)`
`void` `skipBytes(int numBytes)`
`void` `sync()` Synchronize file contents with disk.
`protected void` `syncDataOnlyInternal()`
`protected void` `syncInternal()`
`void` `truncate(long toSize)`
`protected SequentialWriter.TransactionalProxy` `txnProxy()`

### Methods inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus

`applyToChannel, flush, order, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUnsignedVInt, writeUTF, writeVInt`

### Methods inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus

`newDefaultChannel, retrieveTemporaryBuffer`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### bufferOffset

    protected long bufferOffset

#### fchannel

    protected final java.nio.channels.FileChannel fchannel

#### lastFlushOffset

    protected long lastFlushOffset

#### runPostFlush

    protected java.lang.Runnable runPostFlush

### Constructor Detail

#### SequentialWriter

    public SequentialWriter(java.io.File file)

Create heap-based, non-compressed SequenialWriter with default buffer size(64k).

Parameters:
  `file` - File to write

#### SequentialWriter

    public SequentialWriter(java.io.File file,
                            SequentialWriterOption option)

Create SequentialWriter for given file with specific writer option.

Parameters:
  `file` - File to write
  `option` - Writer option

### Method Detail

#### skipBytes

    public void skipBytes(int numBytes)
                   throws java.io.IOException

Throws:
  `java.io.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(java.lang.Runnable 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`

#### 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 java.lang.String getPath()

#### 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 java.lang.Throwable commit(java.lang.Throwable accumulate)

Specified by:
  `commit` in interface `Transactional`

#### abort

    public final java.lang.Throwable abort(java.lang.Throwable accumulate)

Specified by:
  `abort` in interface `Transactional`

#### close

    public final void close()

Specified by:
  `close` in interface `java.io.Closeable`
Specified by:
  `close` in interface `java.lang.AutoCloseable`
Specified by:
  `close` in interface `Transactional`
Overrides:
  `close` in class `BufferedDataOutputStreamPlus`

#### finish

    public final void finish()

#### txnProxy

    protected SequentialWriter.TransactionalProxy txnProxy()