java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.nd.db.ChunkWriter

public class ChunkWriter extends Object
Combines sequential small writes into larger writes and that ensures that writes don't happen faster than a certain maximum rate.
  • Constructor Details

    • ChunkWriter

      public ChunkWriter(int bufferSize, double maxBytesPerMillisecond, ChunkWriter.WriteCallback callback)
      Constructs a new ChunkWriter
      Parameters:
      bufferSize - 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 writes
  • Method Details

    • write

      public boolean write(long position, byte[] data) throws IOException
      Writes the given bytes to the given file position.
      Returns:
      true iff any attempt was made to interrupt the thread using Thread.interrupt(). The write succeeds regardless of the return value.
      Throws:
      IOException - if unable to perform the write
    • flush

      public boolean flush() throws IOException
      Flushes any outstanding writes to disk immediately.
      Returns:
      true iff any attempt was made to interrupt the thread using Thread.interrupt(). The write succeeds regardless of the return value.
      Throws:
      IOException - if unable to perform the write
    • setSleepFunction

      public void setSleepFunction(ChunkWriter.SleepCallback callback)
      Overrides the sleep callback function.
    • getBytesWritten

      public long getBytesWritten()
      Returns the total number of bytes written
    • getTotalWriteTimeMs

      public long getTotalWriteTimeMs()
      Returns the total time spent in calls to ChunkWriter.WriteCallback.write(ByteBuffer, long).