private static void skipField(DataInput in, int bits) throws IOException { switch (bits & TYPE_MASK) { case BYTE_ARR: case STRING: final int length = in.readVInt(); in.skipBytes(length); break; case NUMERIC_INT: in.readZInt(); break; case NUMERIC_FLOAT: readZFloat(in); break; case NUMERIC_LONG: readTLong(in); break; case NUMERIC_DOUBLE: readZDouble(in); break; default: throw new AssertionError("Unknown type flag: " + Integer.toHexString(bits)); } }
byte b = readByte(); if (b >= 0) return b; long i = b & 0x7FL; b = readByte(); i |= (b & 0x7FL) << 7; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 14; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 21; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 28; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 35; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 42; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 49; if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 56; if (b >= 0) return i; if (allowNegative) { b = readByte();
/** Reads one BYTE1/2/4 label from the provided {@link DataInput}. */ public int readLabel(DataInput in) throws IOException { final int v; if (inputType == INPUT_TYPE.BYTE1) { // Unsigned byte: v = in.readByte()&0xFF; } else if (inputType == INPUT_TYPE.BYTE2) { // Unsigned short: v = in.readShort()&0xFFFF; } else { v = in.readVInt(); } return v; }
@Override public boolean load(DataInput input) throws IOException { count = input.readVLong(); this.fst = new FST<>(input, new PairOutputs<>(PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton())); maxAnalyzedPathsForOneInput = input.readVInt(); hasPayloads = input.readByte() == 1; return true; }
private static void readField(DataInput in, StoredFieldVisitor visitor, FieldInfo info, int bits) throws IOException { switch (bits & TYPE_MASK) { case BYTE_ARR: int length = in.readVInt(); byte[] data = new byte[length]; in.readBytes(data, 0, length); visitor.binaryField(info, data); break; case STRING: length = in.readVInt(); data = new byte[length]; in.readBytes(data, 0, length); visitor.stringField(info, data); break; case NUMERIC_INT: visitor.intField(info, in.readZInt()); break; case NUMERIC_FLOAT: visitor.floatField(info, readZFloat(in)); break; case NUMERIC_LONG: visitor.longField(info, readTLong(in)); break; case NUMERIC_DOUBLE: visitor.doubleField(info, readZDouble(in)); break; default: throw new AssertionError("Unknown type flag: " + Integer.toHexString(bits)); } }
if (in.readByte() == 1) { throw new CorruptIndexException("Cannot read packed FSTs anymore", in); if (in.readByte() == 1) { int numBytes = in.readVInt(); emptyBytes.copyBytes(in, numBytes); emptyOutput = null; final byte t = in.readByte(); switch(t) { case 0: throw new IllegalStateException("invalid input type " + t); startNode = in.readVLong(); if (version < VERSION_NO_NODE_ARC_COUNTS) { in.readVLong(); in.readVLong(); in.readVLong(); long numBytes = in.readVLong(); if (numBytes > 1 << maxBlockBits) { in.readBytes(bytesArray, 0, bytesArray.length);
static Checkpoint readCheckpointV6_4_0(final DataInput in) throws IOException { final long offset = in.readLong(); final int numOps = in.readInt(); final long generation = in.readLong(); final long minSeqNo = in.readLong(); final long maxSeqNo = in.readLong(); final long globalCheckpoint = in.readLong(); final long minTranslogGeneration = in.readLong(); final long trimmedAboveSeqNo = in.readLong(); return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo); }
@Override public void skipOutput(DataInput in) throws IOException { int bits = in.readByte() & 0xff; int bit0 = bits & 1; int bit1 = bits & 2; int bit2 = bits & 4; int bytesSize = (bits >>> 3); if (bit1 > 0 && bytesSize == 0) { // determine extra length bytesSize = in.readVInt(); } if (bit0 > 0) { // not all-zero case for (int pos = 0; pos < longsSize; pos++) { in.readVLong(); } } if (bit1 > 0) { // bytes exists in.skipBytes(bytesSize); } if (bit2 > 0) { // stats exist int code = in.readVInt(); if (hasPos && (code & 1) == 0) { in.readVLong(); } } }
/** * Reads a double in a variable-length format. Reads between one and * nine bytes. Small integral values typically take fewer bytes. */ static double readZDouble(DataInput in) throws IOException { int b = in.readByte() & 0xFF; if (b == 0xFF) { // negative value return Double.longBitsToDouble(in.readLong()); } else if (b == 0xFE) { // float return Float.intBitsToFloat(in.readInt()); } else if ((b & 0x80) != 0) { // small integer [-1..124] return (b & 0x7f) - 1; } else { // positive double long bits = ((long) b) << 56 | ((in.readInt() & 0xFFFFFFFFL) << 24) | ((in.readShort() & 0xFFFFL) << 8) | (in.readByte() & 0xFFL); return Double.longBitsToDouble(bits); } }
/** * Reads a Map<String,String> previously written * with {@link DataOutput#writeMapOfStrings(Map)}. * @return An immutable map containing the written contents. */ public Map<String,String> readMapOfStrings() throws IOException { int count = readVInt(); if (count == 0) { return Collections.emptyMap(); } else if (count == 1) { return Collections.singletonMap(readString(), readString()); } else { Map<String,String> map = count > 10 ? new HashMap<>() : new TreeMap<>(); for (int i = 0; i < count; i++) { final String key = readString(); final String val = readString(); map.put(key, val); } return Collections.unmodifiableMap(map); } }
/** Like {@link * #checkHeader(DataInput,String,int,int)} except this * version assumes the first int has already been read * and validated from the input. */ public static int checkHeaderNoMagic(DataInput in, String codec, int minVersion, int maxVersion) throws IOException { final String actualCodec = in.readString(); if (!actualCodec.equals(codec)) { throw new CorruptIndexException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec, in); } final int actualVersion = in.readInt(); if (actualVersion < minVersion) { throw new IndexFormatTooOldException(in, actualVersion, minVersion, maxVersion); } if (actualVersion > maxVersion) { throw new IndexFormatTooNewException(in, actualVersion, minVersion, maxVersion); } return actualVersion; }
Direct8(int packedIntsVersion, DataInput in, int valueCount) throws IOException { this(valueCount); in.readBytes(values, 0, valueCount); // because packed ints have not always been byte-aligned final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, 8) - 1L * valueCount); for (int i = 0; i < remaining; ++i) { in.readByte(); } }
private static void skipField(DataInput in, int bits) throws IOException { switch (bits & TYPE_MASK) { case BYTE_ARR: case STRING: final int length = in.readVInt(); in.skipBytes(length); break; case NUMERIC_INT: case NUMERIC_FLOAT: in.readInt(); break; case NUMERIC_LONG: case NUMERIC_DOUBLE: in.readLong(); break; default: throw new AssertionError("Unknown type flag: " + Integer.toHexString(bits)); } }
Packed8ThreeBlocks(int packedIntsVersion, DataInput in, int valueCount) throws IOException { this(valueCount); in.readBytes(blocks, 0, 3 * valueCount); }
/** * Reads a float in a variable-length format. Reads between one and * five bytes. Small integral values typically take fewer bytes. */ static float readZFloat(DataInput in) throws IOException { int b = in.readByte() & 0xFF; if (b == 0xFF) { // negative value return Float.intBitsToFloat(in.readInt()); } else if ((b & 0x80) != 0) { // small integer [-1..125] return (b & 0x7f) - 1; } else { // positive float int bits = b << 24 | ((in.readShort() & 0xFFFF) << 8) | (in.readByte() & 0xFF); return Float.intBitsToFloat(bits); } }
@Override public Long read(DataInput in) throws IOException { long v = in.readVLong(); if (v == 0) { return NO_OUTPUT; } else { return v; } }