public void write(DataOutput out) throws IOException { if (firstKey == null) { Utils.writeVInt(out, 0); return; } DataOutputBuffer dob = new DataOutputBuffer(); Utils.writeVInt(dob, firstKey.size()); dob.write(firstKey.buffer()); Utils.writeVInt(out, dob.size()); out.write(dob.getData(), 0, dob.getLength()); for (TFileIndexEntry entry : index) { dob.reset(); entry.write(dob); Utils.writeVInt(out, dob.getLength()); out.write(dob.getData(), 0, dob.getLength()); } } }
/** * Get a scanner that covers a portion of TFile based on keys. * * @param beginKey * Begin key of the scan (inclusive). If null, scan from the first * key-value entry of the TFile. * @param endKey * End key of the scan (exclusive). If null, scan up to the last * key-value entry of the TFile. * @return The actual coverage of the returned scanner will cover all keys * greater than or equal to the beginKey and less than the endKey. * @throws IOException */ public Scanner createScannerByKey(byte[] beginKey, byte[] endKey) throws IOException { return createScannerByKey((beginKey == null) ? null : new ByteArray(beginKey, 0, beginKey.length), (endKey == null) ? null : new ByteArray(endKey, 0, endKey.length)); }
public RawComparable getLastKey() { if (index.size() == 0) { return null; } return new ByteArray(index.get(index.size() - 1).buffer()); }
/** * Compare the entry key to another key. Synonymous to compareTo(new * ByteArray(buf, offset, length) * * @param buf * The key buffer * @param offset * offset into the key buffer. * @param length * the length of the key. * @return comparison result between the entry key with the input key. */ public int compareTo(byte[] buf, int offset, int length) { return compareTo(new ByteArray(buf, offset, length)); }
public void write(DataOutput out) throws IOException { if (firstKey == null) { Utils.writeVInt(out, 0); return; } DataOutputBuffer dob = new DataOutputBuffer(); Utils.writeVInt(dob, firstKey.size()); dob.write(firstKey.buffer()); Utils.writeVInt(out, dob.size()); out.write(dob.getData(), 0, dob.getLength()); for (TFileIndexEntry entry : index) { dob.reset(); entry.write(dob); Utils.writeVInt(out, dob.getLength()); out.write(dob.getData(), 0, dob.getLength()); } } }
/** * Move the cursor to the first entry whose key is strictly greater than * the input key. The entry returned by the previous entry() call will be * invalid. * * @param key * The input key * @param keyOffset * offset in the key buffer. * @param keyLen * key buffer length. * @throws IOException */ public void upperBound(byte[] key, int keyOffset, int keyLen) throws IOException { seekTo(new ByteArray(key, keyOffset, keyLen), true); }
public void write(DataOutput out) throws IOException { if (firstKey == null) { Utils.writeVInt(out, 0); return; } DataOutputBuffer dob = new DataOutputBuffer(); Utils.writeVInt(dob, firstKey.size()); dob.write(firstKey.buffer()); Utils.writeVInt(out, dob.size()); out.write(dob.getData(), 0, dob.getLength()); for (TFileIndexEntry entry : index) { dob.reset(); entry.write(dob); Utils.writeVInt(out, dob.getLength()); out.write(dob.getData(), 0, dob.getLength()); } } }
/** * Move the cursor to the first entry whose key is greater than or equal * to the input key. The entry returned by the previous entry() call will * be invalid. * * @param key * The input key * @param keyOffset * offset in the key buffer. * @param keyLen * key buffer length. * @throws IOException */ public void lowerBound(byte[] key, int keyOffset, int keyLen) throws IOException { seekTo(new ByteArray(key, keyOffset, keyLen), false); }
public void write(DataOutput out) throws IOException { if (firstKey == null) { Utils.writeVInt(out, 0); return; } DataOutputBuffer dob = new DataOutputBuffer(); Utils.writeVInt(dob, firstKey.size()); dob.write(firstKey.buffer()); Utils.writeVInt(out, dob.size()); out.write(dob.getData(), 0, dob.getLength()); for (TFileIndexEntry entry : index) { dob.reset(); entry.write(dob); Utils.writeVInt(out, dob.getLength()); out.write(dob.getData(), 0, dob.getLength()); } } }
/** * Move the cursor to the first entry whose key is greater than or equal * to the input key. The entry returned by the previous entry() call will * be invalid. * * @param key * The input key * @param keyOffset * offset in the key buffer. * @param keyLen * key buffer length. * @return true if we find an equal key; false otherwise. * @throws IOException */ public boolean seekTo(byte[] key, int keyOffset, int keyLen) throws IOException { return seekTo(new ByteArray(key, keyOffset, keyLen), false); }
public void write(DataOutput out) throws IOException { if (firstKey == null) { Utils.writeVInt(out, 0); return; } DataOutputBuffer dob = new DataOutputBuffer(); Utils.writeVInt(dob, firstKey.size()); dob.write(firstKey.buffer()); Utils.writeVInt(out, dob.size()); out.write(dob.getData(), 0, dob.getLength()); for (TFileIndexEntry entry : index) { dob.reset(); entry.write(dob); Utils.writeVInt(out, dob.getLength()); out.write(dob.getData(), 0, dob.getLength()); } } }
/** * Get a sample key that is within a block whose starting offset is greater * than or equal to the specified offset. * * @param offset * The file offset. * @return the key that fits the requirement; or null if no such key exists * (which could happen if the offset is close to the end of the * TFile). * @throws IOException */ public RawComparable getKeyNear(long offset) throws IOException { int blockIndex = readerBCF.getBlockIndexNear(offset); if (blockIndex == -1) return null; checkTFileDataIndex(); return new ByteArray(tfileIndex.getEntry(blockIndex).key); }
public void write(DataOutput out) throws IOException { if (firstKey == null) { Utils.writeVInt(out, 0); return; } DataOutputBuffer dob = new DataOutputBuffer(); Utils.writeVInt(dob, firstKey.size()); dob.write(firstKey.buffer()); Utils.writeVInt(out, dob.size()); out.write(dob.getData(), 0, dob.getLength()); for (TFileIndexEntry entry : index) { dob.reset(); entry.write(dob); Utils.writeVInt(out, dob.getLength()); out.write(dob.getData(), 0, dob.getLength()); } } }