void writeTo(ReftableOutputStream os) throws IOException { os.beginBlock(blockType); IntList restarts = new IntList(restartCnt); for (Entry entry : entries) { if (entry.restart) { restarts.add(os.bytesWrittenInBlock()); } entry.writeKey(os); entry.writeValue(os); } if (restarts.size() == 0 || restarts.size() > MAX_RESTARTS) { throw new IllegalStateException(); } for (int i = 0; i < restarts.size(); i++) { os.writeInt24(restarts.get(i)); } os.writeInt16(restarts.size()); os.flushBlock(); }
@Override int valueSize() { return 2 * OBJECT_ID_LENGTH + computeVarintSize(name.length) + name.length + computeVarintSize(email.length) + email.length + computeVarintSize(timeSecs) + 2 // tz + computeVarintSize(msg.length) + msg.length; }
/** {@inheritDoc} */ @Override public void write(int b) { ensureBytesAvailableInBlockBuf(1); blockBuf[cur++] = (byte) b; }
void padBetweenBlocksToNextBlock() throws IOException { if (alignBlocks) { long m = size() % blockSize; if (m > 0) { int pad = blockSize - (int) m; ensureBytesAvailableInBlockBuf(pad); Arrays.fill(blockBuf, 0, pad, (byte) 0); out.write(blockBuf, 0, pad); paddingUsed += pad; } } }
private void beginLog() throws IOException { if (logs == null) { finishRefAndObjSections(); // close prior ref blocks and their index, if present. out.flushFileHeader(); out.setBlockSize(logBlockSize); logs = new Section(LOG_BLOCK_TYPE); } }
long bytes = out.size(); if (bytes == 0) { bytes += FILE_HEADER_LEN; long curBlockPos = out.size(); int sz = cur.currentSize(); bytes += sz; bytes += out.estimatePadBetweenBlocks(sz);
private void beginBlock(BlockWriter.Entry entry) throws BlockSizeTooSmallException { byte blockType = entry.blockType(); int bs = out.bytesAvailableInBlock(); cur = new BlockWriter(blockType, idx.keyType, bs, restartInterval); cur.mustAdd(entry); }
/** * Finish writing the reftable by writing its trailer. * * @return {@code this} * @throws java.io.IOException * if reftable cannot be written. */ public ReftableWriter finish() throws IOException { finishRefAndObjSections(); finishLogSection(); writeFileFooter(); out.finishFile(); stats = new Stats(this, out); out = null; obj2ref = null; cur = null; refs = null; objs = null; logs = null; return this; }
out = new ReftableOutputStream(os, refBlockSize, alignBlocks); refs = new Section(REF_BLOCK_TYPE); if (indexObjects) {
private void beginLog() throws IOException { if (logs == null) { finishRefAndObjSections(); // close prior ref blocks and their index, if present. out.flushFileHeader(); out.setBlockSize(logBlockSize); logs = new Section(LOG_BLOCK_TYPE); } }
void padBetweenBlocksToNextBlock() throws IOException { if (alignBlocks) { long m = size() % blockSize; if (m > 0) { int pad = blockSize - (int) m; ensureBytesAvailableInBlockBuf(pad); Arrays.fill(blockBuf, 0, pad, (byte) 0); out.write(blockBuf, 0, pad); paddingUsed += pad; } } }
long bytes = out.size(); if (bytes == 0) { bytes += FILE_HEADER_LEN; long curBlockPos = out.size(); int sz = cur.currentSize(); bytes += sz; bytes += out.estimatePadBetweenBlocks(sz);
private void beginBlock(BlockWriter.Entry entry) throws BlockSizeTooSmallException { byte blockType = entry.blockType(); int bs = out.bytesAvailableInBlock(); cur = new BlockWriter(blockType, idx.keyType, bs, restartInterval); cur.mustAdd(entry); }
/** * Finish writing the reftable by writing its trailer. * * @return {@code this} * @throws java.io.IOException * if reftable cannot be written. */ public ReftableWriter finish() throws IOException { finishRefAndObjSections(); finishLogSection(); writeFileFooter(); out.finishFile(); stats = new Stats(this, out); out = null; obj2ref = null; cur = null; refs = null; objs = null; logs = null; return this; }
out = new ReftableOutputStream(os, refBlockSize, alignBlocks); refs = new Section(REF_BLOCK_TYPE); if (indexObjects) {
void writeTo(ReftableOutputStream os) throws IOException { os.beginBlock(blockType); IntList restarts = new IntList(restartCnt); for (Entry entry : entries) { if (entry.restart) { restarts.add(os.bytesWrittenInBlock()); } entry.writeKey(os); entry.writeValue(os); } if (restarts.size() == 0 || restarts.size() > MAX_RESTARTS) { throw new IllegalStateException(); } for (int i = 0; i < restarts.size(); i++) { os.writeInt24(restarts.get(i)); } os.writeInt16(restarts.size()); os.flushBlock(); }
/** {@inheritDoc} */ @Override public void write(byte[] b, int off, int cnt) { ensureBytesAvailableInBlockBuf(cnt); System.arraycopy(b, off, blockBuf, cur, cnt); cur += cnt; }
@Override int valueSize() { return computeVarintSize(blockPosition); }
void writeInt16(int val) { ensureBytesAvailableInBlockBuf(2); NB.encodeInt16(blockBuf, cur, val); cur += 2; }
@Override int valueSize() { int cnt = blockPos.size(); if (cnt == 0) { return computeVarintSize(0); } int n = 0; if (cnt > VALUE_TYPE_MASK) { n += computeVarintSize(cnt); } n += computeVarintSize(blockPos.get(0)); for (int j = 1; j < cnt; j++) { long prior = blockPos.get(j - 1); long b = blockPos.get(j); n += computeVarintSize(b - prior); } return n; }