org.apache.cassandra.io.util
Class SequentialWriter

java.lang.Object
  extended by java.io.OutputStream
      extended by org.apache.cassandra.io.util.SequentialWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
CompressedSequentialWriter

public class SequentialWriter
extends java.io.OutputStream


Nested Class Summary
protected static class SequentialWriter.BufferedFileWriterMark
          Class to hold a mark to the position of the file
 
Field Summary
protected  byte[] buffer
           
protected  long bufferOffset
           
protected  long current
           
protected  boolean isDirty
           
protected  java.io.RandomAccessFile out
           
 java.io.DataOutputStream stream
           
protected  boolean syncNeeded
           
protected  int validBufferBytes
           
 
Constructor Summary
SequentialWriter(java.io.File file, int bufferSize, boolean skipIOCache)
           
 
Method Summary
 void close()
           
 byte[] digest()
          Return the digest associated to this file or null if no digest was created.
 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 getOnDiskFilePointer()
          Return the current file pointer of the underlying on-disk file.
 java.lang.String getPath()
           
 long length()
           
 FileMark mark()
           
static SequentialWriter open(java.io.File file)
           
static SequentialWriter open(java.io.File file, boolean skipIOCache)
           
static SequentialWriter open(java.io.File file, int bufferSize, boolean skipIOCache)
           
protected  void reBuffer()
           
 void resetAndTruncate(FileMark mark)
           
protected  void resetBuffer()
           
 void setComputeDigest()
          Turn on digest computation on this writer.
 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)
           
 void write(int value)
           
 
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 java.io.DataOutputStream stream
Constructor Detail

SequentialWriter

public SequentialWriter(java.io.File file,
                        int bufferSize,
                        boolean skipIOCache)
Method Detail

open

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

open

public static SequentialWriter open(java.io.File file,
                                    boolean skipIOCache)

open

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

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

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)

truncate

public void truncate(long toSize)

close

public void close()
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream

setComputeDigest

public void setComputeDigest()
Turn on digest computation on this writer. This can only be called before any data is written to this write, otherwise an IllegalStateException is thrown.


digest

public byte[] digest()
Return the digest associated to this file or null if no digest was created. This can only be called once the file is fully created, i.e. after close() has been called. Otherwise an IllegalStateException is thrown.



Copyright © 2012 The Apache Software Foundation