Package io.permazen.kv.array
Class ArrayKVWriter
java.lang.Object
io.permazen.kv.array.ArrayKVWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
ConstructorDescriptionArrayKVWriter
(OutputStream indxOutput, OutputStream keysOutput, OutputStream valsOutput) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close all three outputs.void
flush()
Flush all three outputs.int
Get the number of bytes written so far to the index file.int
Get the number of bytes written so far to the key data file.int
Get the number of bytes written so far to the value data file.void
writeKV
(byte[] key, byte[] val) Write out the next key/value pair.void
writeMerged
(KVStore kvstore, Iterator<KVPair> kvIterator, Mutations mutations) Merge the given key/value pair iteration with the specified mutations and write out the merged combination.
-
Constructor Details
-
ArrayKVWriter
Constructor.- Parameters:
indxOutput
- index file outputkeysOutput
- key data file outputvalsOutput
- 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
Write out the next key/value pair.- Parameters:
key
- keyval
- value- Throws:
IllegalArgumentException
- ifkey
is out of order (i.e., not strictly greater then the previous key)IllegalArgumentException
- ifkey
orval
is nullIllegalStateException
- if either the key or data file would grow larger than 231-1 bytesIOException
- 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 invokeKVStore.encodeCounter()
andKVStore.decodeCounter()
in order to handle counter adjustments.- Parameters:
kvstore
- callback for encoding and decoding counter valueskvIterator
- key/value pairs - must be sorted in ordermutations
- mutations to apply- Throws:
IllegalArgumentException
- if any parameter is nullIllegalArgumentException
- ifkvs
iterates out of orderIllegalStateException
- if either the key or data file would grow larger than 231-1 bytesIOException
- if an I/O error occurrs
-
flush
Flush all three outputs.- Throws:
IOException
- if an I/O error occurrs
-
close
Close all three outputs.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurrs
-