public class ChunkWriter
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ChunkWriter.SleepCallback |
static interface |
ChunkWriter.WriteCallback
Interface used to perform the uninterruptable writes when the buffer fills up.
|
| Constructor and Description |
|---|
ChunkWriter(int bufferSize,
double maxBytesPerMillisecond,
ChunkWriter.WriteCallback callback)
Constructs a new
ChunkWriter |
| Modifier and Type | Method and Description |
|---|---|
boolean |
flush()
Flushes any outstanding writes to disk immediately.
|
long |
getBytesWritten()
Returns the total number of bytes written
|
long |
getTotalWriteTimeMs()
Returns the total time spent in calls to
ChunkWriter.WriteCallback.write(ByteBuffer, long). |
void |
setSleepFunction(ChunkWriter.SleepCallback callback)
Overrides the sleep callback function.
|
boolean |
write(long position,
byte[] data)
Writes the given bytes to the given file position.
|
public ChunkWriter(int bufferSize,
double maxBytesPerMillisecond,
ChunkWriter.WriteCallback callback)
ChunkWriterbufferSize - size of the write buffer (the maximum number of bytes that will be written in a single write).maxBytesPerMillisecond - the maximum number of bytes that will be written per second. If an attempt is made to write more
rapidly than this, the thread will be put to sleep.callback - will be invoked to perform the writespublic boolean write(long position,
byte[] data)
throws java.io.IOException
Thread.interrupt(). The write
succeeds regardless of the return value.java.io.IOException - if unable to perform the writepublic boolean flush()
throws java.io.IOException
Thread.interrupt(). The write
succeeds regardless of the return value.java.io.IOException - if unable to perform the writepublic void setSleepFunction(ChunkWriter.SleepCallback callback)
public long getBytesWritten()
public long getTotalWriteTimeMs()
ChunkWriter.WriteCallback.write(ByteBuffer, long).