public class SequentialWriter extends BufferedDataOutputStreamPlus implements Transactional
Modifier and Type | Class and Description |
---|---|
protected static class |
SequentialWriter.BufferedFileWriterMark
Class to hold a mark to the position of the file
|
protected class |
SequentialWriter.TransactionalProxy |
Transactional.AbstractTransactional
Modifier and Type | Field and Description |
---|---|
protected long |
bufferOffset |
protected java.nio.channels.FileChannel |
fchannel |
protected long |
lastFlushOffset |
protected java.lang.Runnable |
runPostFlush |
buffer
channel
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.
|
SequentialWriter(java.io.File file,
SequentialWriterOption option,
boolean strictFlushing)
Create SequentialWriter for given file with specific writer option.
|
Modifier and Type | Method and Description |
---|---|
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() |
int |
writeDirectlyToChannel(java.nio.ByteBuffer buf) |
flush, order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
newDefaultChannel, retrieveTemporaryBuffer
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
write, writeUnsignedVInt, writeVInt
protected long bufferOffset
protected final java.nio.channels.FileChannel fchannel
protected long lastFlushOffset
protected java.lang.Runnable runPostFlush
public SequentialWriter(java.io.File file)
file
- File to writepublic SequentialWriter(java.io.File file, SequentialWriterOption option)
file
- File to writeoption
- Writer optionpublic SequentialWriter(java.io.File file, SequentialWriterOption option, boolean strictFlushing)
file
- option
- strictFlushing
- public void skipBytes(int numBytes) throws java.io.IOException
java.io.IOException
public void sync()
protected void syncDataOnlyInternal()
protected void syncInternal()
protected void doFlush(int count)
doFlush
in class BufferedDataOutputStreamPlus
public void setPostFlushListener(java.lang.Runnable runPostFlush)
protected void flushData()
FSWriteError
- on any I/O error.public boolean hasPosition()
DataOutputPlus
true
, otherwise false
.hasPosition
in interface DataOutputPlus
public long position()
DataOutputPlus
DataOutputPlus.hasPosition()
.position
in interface DataOutputPlus
public long getOnDiskFilePointer()
public long getEstimatedOnDiskBytesWritten()
public long length()
public java.lang.String getPath()
protected void resetBuffer()
protected long current()
public DataPosition mark()
public void resetAndTruncate(DataPosition mark)
public long getLastFlushOffset()
public void truncate(long toSize)
public boolean isOpen()
public final void prepareToCommit()
prepareToCommit
in interface Transactional
public final java.lang.Throwable commit(java.lang.Throwable accumulate)
commit
in interface Transactional
public final java.lang.Throwable abort(java.lang.Throwable accumulate)
abort
in interface Transactional
public final void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface Transactional
close
in class BufferedDataOutputStreamPlus
public int writeDirectlyToChannel(java.nio.ByteBuffer buf) throws java.io.IOException
java.io.IOException
public final void finish()
protected SequentialWriter.TransactionalProxy txnProxy()
Copyright © 2009-2022 The Apache Software Foundation