public TFileMeta(DataInput in) throws IOException { version = new Version(in); if (!version.compatibleWith(TFile.API_VERSION)) { throw new RuntimeException("Incompatible TFile fileVersion."); } recordCount = Utils.readVLong(in); strComparator = Utils.readString(in); comparator = makeComparator(strComparator); }
public void write(DataOutput out) throws IOException { TFile.API_VERSION.write(out); Utils.writeVLong(out, recordCount); Utils.writeString(out, strComparator); }
/** * @param key * input key. * @return the ID of the first block that contains key >= input key. Or -1 * if no such block exists. */ public int lowerBound(RawComparable key) { if (comparator == null) { throw new RuntimeException("Cannot search in unsorted TFile"); } if (firstKey == null) { return -1; // not found } int ret = Utils.lowerBound(index, key, comparator); if (ret == index.size()) { return -1; } return ret; }
public void write(DataOutput out) throws IOException { Utils.writeVInt(out, key.length); out.write(key, 0, key.length); Utils.writeVLong(out, kvEntries); } }
public DataIndex(DataInput in) throws IOException { defaultCompressionAlgorithm = Compression.getCompressionAlgorithmByName(Utils.readString(in)); int n = Utils.readVInt(in); listRegions = new ArrayList<BlockRegion>(n); for (int i = 0; i < n; i++) { BlockRegion region = new BlockRegion(in); listRegions.add(region); } }
public void write(DataOutput out) throws IOException { Utils.writeString(out, defaultCompressionAlgorithm.getName()); Utils.writeVInt(out, listRegions.size()); for (BlockRegion region : listRegions) { region.write(out); } } }
/** * @param key * input key. * @return the ID of the first block that contains key > input key. Or -1 * if no such block exists. */ public int upperBound(RawComparable key) { if (comparator == null) { throw new RuntimeException("Cannot search in unsorted TFile"); } if (firstKey == null) { return -1; // not found } int ret = Utils.upperBound(index, key, comparator); if (ret == index.size()) { return -1; } return ret; }
public void write(DataOutput out) throws IOException { Utils.writeVLong(out, offset); Utils.writeVLong(out, compressedSize); Utils.writeVLong(out, rawSize); }
/** * Constructor. * * @param out * the underlying output stream. * @param size * The total # of bytes to be written as a single chunk. * @throws java.io.IOException * if an I/O error occurs. */ public SingleChunkEncoder(DataOutputStream out, int size) throws IOException { this.out = out; this.remain = size; Utils.writeVInt(out, size); }
/** * Reading the length of next chunk. * * @throws java.io.IOException * when no more data is available. */ private void readLength() throws IOException { remain = Utils.readVInt(in); if (remain >= 0) { lastChunk = true; } else { remain = -remain; } }
public void write(DataOutput out) throws IOException { Utils.writeString(out, defaultPrefix + metaName); Utils.writeString(out, compressionAlgorithm.getName()); region.write(out); } }
public MetaIndexEntry(DataInput in) throws IOException { String fullMetaName = Utils.readString(in); if (fullMetaName.startsWith(defaultPrefix)) { metaName = fullMetaName.substring(defaultPrefix.length(), fullMetaName .length()); } else { throw new IOException("Corrupted Meta region Index"); } compressionAlgorithm = Compression.getCompressionAlgorithmByName(Utils.readString(in)); region = new BlockRegion(in); }
public void write(DataOutput out) throws IOException { Utils.writeVInt(out, key.length); out.write(key, 0, key.length); Utils.writeVLong(out, kvEntries); } }
public DataIndex(DataInput in) throws IOException { defaultCompressionAlgorithm = Compression.getCompressionAlgorithmByName(Utils.readString(in)); int n = Utils.readVInt(in); listRegions = new ArrayList<BlockRegion>(n); for (int i = 0; i < n; i++) { BlockRegion region = new BlockRegion(in); listRegions.add(region); } }
public void write(DataOutput out) throws IOException { Utils.writeString(out, defaultCompressionAlgorithm.getName()); Utils.writeVInt(out, listRegions.size()); for (BlockRegion region : listRegions) { region.write(out); } } }
public Reader.Location getLocationByRecordNum(long recNum) { int idx = Utils.upperBound(recordNumIndex, recNum); long lastRecNum = (idx == 0)? 0: recordNumIndex.get(idx-1); return new Reader.Location(idx, recNum-lastRecNum); }
/** * Encoding an integer into a variable-length encoding format. Synonymous to * <code>Utils#writeVLong(out, n)</code>. * * @param out * output stream * @param n * The integer to be encoded * @throws IOException * @see Utils#writeVLong(DataOutput, long) */ public static void writeVInt(DataOutput out, int n) throws IOException { writeVLong(out, n); }