MCPcopy Create free account
hub / github.com/cschanck/single-file-java / append

Method append

src/main/java/org/sfj/ChiseledMap.java:298–320  ·  view source on GitHub ↗
(K key, V v)

Source from the content-addressed store, hash-verified

296 }
297
298 private synchronized long append(K key, V v) throws IOException {
299 // core append path for all mutations
300
301 // encode to byte buffer, record length
302 ByteBuffer payload = encoder.encode(key, v);
303 lenBuffer.clear();
304 lenBuffer.putInt(0, payload.remaining());
305
306 // create crc checksum
307 digest.reset();
308 digest.update(payload.slice());
309 int d = (int) (digest.getValue() & DIGEST_MASK);
310 digestBuffer.clear();
311 digestBuffer.putInt(0, d);
312
313 // return the current write pos
314 long ret = currentWritePos;
315 int fp = Integer.BYTES + Integer.BYTES + payload.remaining();
316 write(lenBuffer, payload, digestBuffer, fp);
317 this.currentWritePos = currentWritePos + fp;
318 entriesOnDisk++;
319 return ret;
320 }
321
322 private void write(ByteBuffer len, ByteBuffer arr, ByteBuffer d, int fp) throws IOException {
323 // write the data into the buffer, flushing if necessary

Callers 3

ioUnsetMethod · 0.95
ioSetMethod · 0.95
ioGetSetMethod · 0.95

Calls 4

writeMethod · 0.95
encodeMethod · 0.65
clearMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected