SequentialWriter (apache-cassandra API)
Date: 2014-10-21

org.apache.cassandra.io.util

## Class SequentialWriter

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

- All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel
  Direct Known Subclasses:
    ChecksummedSequentialWriter, CompressedSequentialWriter

      public class SequentialWriter
      extends java.io.OutputStream
      implements java.nio.channels.WritableByteChannel

  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
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `SequentialWriter.BufferedFileWriterMark` Class to hold a mark to the position of the file

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected byte[]` | `buffer`
    `protected long` | `bufferOffset`
    `protected long` | `current`
    `protected boolean` | `isDirty`
    `protected long` | `lastFlushOffset`
    `protected java.io.RandomAccessFile` | `out`
    `DataOutputPlus` | `stream`
    `protected boolean` | `syncNeeded`
    `protected int` | `validBufferBytes`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SequentialWriter(java.io.File file, int bufferSize)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `flush()` If buffer is dirty, flush it's contents to the operating system.
    `protected void` | `flushData()` Override this method instead of overriding flush()
    `protected void` | `flushInternal()`
    `long` | `getFilePointer()`
    `long` | `getLastFlushOffset()`
    `long` | `getOnDiskFilePointer()` Return the current file pointer of the underlying on-disk file.
    `java.lang.String` | `getPath()`
    `boolean` | `isOpen()`
    `long` | `length()`
    `FileMark` | `mark()`
    `static SequentialWriter` | `open(java.io.File file)`
    `static ChecksummedSequentialWriter` | `open(java.io.File file, java.io.File crcPath)`
    `static SequentialWriter` | `open(java.io.File file, int bufferSize)`
    `static CompressedSequentialWriter` | `open(java.lang.String dataFilePath, java.lang.String offsetsPath, CompressionParameters parameters, MetadataCollector sstableMetadataCollector)`
    `protected void` | `reBuffer()`
    `void` | `resetAndTruncate(FileMark mark)`
    `protected void` | `resetBuffer()`
    `void` | `sync()` Synchronize file contents with disk.
    `protected void` | `syncDataOnlyInternal()`
    `protected void` | `syncInternal()`
    `void` | `truncate(long toSize)`
    `void` | `write(byte[] buffer)`
    `void` | `write(byte[] data, int offset, int length)`
    `int` | `write(java.nio.ByteBuffer src)`
    `void` | `write(int value)`
    `void` | `writeFullChecksum(Descriptor descriptor)`

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

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

- - ### Field Detail

    - #### isDirty

          protected boolean isDirty

    - #### syncNeeded

          protected boolean syncNeeded

    - #### buffer

          protected byte[] buffer

    - #### current

          protected long current

    - #### bufferOffset

          protected long bufferOffset

    - #### validBufferBytes

          protected int validBufferBytes

    - #### out

          protected final java.io.RandomAccessFile out

    - #### stream

          public final DataOutputPlus stream

    - #### lastFlushOffset

          protected long lastFlushOffset

  - ### Constructor Detail

    - #### SequentialWriter

          public SequentialWriter(java.io.File file,
                          int bufferSize)

  - ### Method Detail

    - #### open

          public static SequentialWriter open(java.io.File file)

    - #### open

          public static SequentialWriter open(java.io.File file,
                              int bufferSize)

    - #### open

          public static ChecksummedSequentialWriter open(java.io.File file,
                                         java.io.File crcPath)

    - #### open

          public static CompressedSequentialWriter open(java.lang.String dataFilePath,
                                        java.lang.String offsetsPath,
                                        CompressionParameters parameters,
                                        MetadataCollector sstableMetadataCollector)

    - #### write

          public void write(int value)
                     throws java.nio.channels.ClosedChannelException

      Specified by:
        `write` in class `java.io.OutputStream`
      Throws:
        `java.nio.channels.ClosedChannelException`

    - #### write

          public void write(byte[] buffer)
                     throws java.nio.channels.ClosedChannelException

      Overrides:
        `write` in class `java.io.OutputStream`
      Throws:
        `java.nio.channels.ClosedChannelException`

    - #### write

          public void write(byte[] data,
                   int offset,
                   int length)
                     throws java.nio.channels.ClosedChannelException

      Overrides:
        `write` in class `java.io.OutputStream`
      Throws:
        `java.nio.channels.ClosedChannelException`

    - #### write

          public int write(java.nio.ByteBuffer src)
                    throws java.io.IOException

      Specified by:
        `write` in interface `java.nio.channels.WritableByteChannel`
      Throws:
        `java.io.IOException`

    - #### sync

          public void sync()

      Synchronize file contents with disk.

    - #### syncDataOnlyInternal

          protected void syncDataOnlyInternal()

    - #### syncInternal

          protected void syncInternal()

    - #### flush

          public void flush()

      If buffer is dirty, flush it's contents to the operating system. Does not imply fsync(). Currently, for implementation reasons, this also invalidates the buffer.
      Specified by:
        `flush` in interface `java.io.Flushable`
      Overrides:
        `flush` in class `java.io.OutputStream`

    - #### flushInternal

          protected void flushInternal()

    - #### flushData

          protected void flushData()

      Override this method instead of overriding flush()
      Throws:
        `FSWriteError` - on any I/O error.

    - #### getFilePointer

          public long getFilePointer()

    - #### getOnDiskFilePointer

          public long getOnDiskFilePointer()

      Return 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

    - #### length

          public long length()

    - #### getPath

          public java.lang.String getPath()

    - #### reBuffer

          protected void reBuffer()

    - #### resetBuffer

          protected void resetBuffer()

    - #### mark

          public FileMark mark()

    - #### resetAndTruncate

          public void resetAndTruncate(FileMark mark)

    - #### getLastFlushOffset

          public long getLastFlushOffset()

    - #### truncate

          public void truncate(long toSize)

    - #### isOpen

          public boolean isOpen()

      Specified by:
        `isOpen` in interface `java.nio.channels.Channel`

    - #### close

          public void close()

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `java.nio.channels.Channel`
      Overrides:
        `close` in class `java.io.OutputStream`

    - #### writeFullChecksum

          public void writeFullChecksum(Descriptor descriptor)

Copyright © 2014 The Apache Software Foundation