Class ArrayKVWriter

java.lang.Object
io.permazen.kv.array.ArrayKVWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class ArrayKVWriter extends Object implements Closeable
Writes ArrayKVStore index, key, and value data, given a sorted sequence of key/value pairs.

Key and value data must not exceed 2GB (each separately).

  • Constructor Details

    • ArrayKVWriter

      public ArrayKVWriter(OutputStream indxOutput, OutputStream keysOutput, OutputStream valsOutput)
      Constructor.
      Parameters:
      indxOutput - index file output
      keysOutput - key data file output
      valsOutput - value data file output
  • Method Details

    • getIndxLength

      public int getIndxLength()
      Get the number of bytes written so far to the index file.
      Returns:
      length of the index file
    • getKeysLength

      public int getKeysLength()
      Get the number of bytes written so far to the key data file.
      Returns:
      length of the key data file
    • getValsLength

      public int getValsLength()
      Get the number of bytes written so far to the value data file.
      Returns:
      length of the value data file
    • writeKV

      public void writeKV(byte[] key, byte[] val) throws IOException
      Write out the next key/value pair.
      Parameters:
      key - key
      val - value
      Throws:
      IllegalArgumentException - if key is out of order (i.e., not strictly greater then the previous key)
      IllegalArgumentException - if key or val is null
      IllegalStateException - if either the key or data file would grow larger than 231-1 bytes
      IOException - if an I/O error occurrs
    • writeMerged

      public void writeMerged(KVStore kvstore, Iterator<KVPair> kvIterator, Mutations mutations) throws IOException
      Merge the given key/value pair iteration with the specified mutations and write out the merged combination. What's written is the result of the key/value iteration with the mutations applied.

      The KVStore parameter will only be used to invoke KVStore.encodeCounter() and KVStore.decodeCounter() in order to handle counter adjustments.

      Parameters:
      kvstore - callback for encoding and decoding counter values
      kvIterator - key/value pairs - must be sorted in order
      mutations - mutations to apply
      Throws:
      IllegalArgumentException - if any parameter is null
      IllegalArgumentException - if kvs iterates out of order
      IllegalStateException - if either the key or data file would grow larger than 231-1 bytes
      IOException - if an I/O error occurrs
    • flush

      public void flush() throws IOException
      Flush all three outputs.
      Throws:
      IOException - if an I/O error occurrs
    • close

      public void close() throws IOException
      Close all three outputs.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurrs