@Override public final int readInt() throws IOException { if (4 <= (bufferLength-bufferPosition)) { return ((buffer[bufferPosition++] & 0xFF) << 24) | ((buffer[bufferPosition++] & 0xFF) << 16) | ((buffer[bufferPosition++] & 0xFF) << 8) | (buffer[bufferPosition++] & 0xFF); } else { return super.readInt(); } }
static <T> void readInts32(IndexInput in, int count, int[] docIDs) throws IOException { for (int i = 0; i < count; i++) { docIDs[i] = in.readInt(); } }
static void readInts32(IndexInput in, int count, IntersectVisitor visitor) throws IOException { for (int i = 0; i < count; i++) { visitor.visit(in.readInt()); } }
@Override public int readInt(long pos) throws IOException { slice.seek(pos); return slice.readInt(); }
@Override public boolean next() throws IOException { if (countLeft >= 0) { if (countLeft == 0) { return false; } countLeft--; } try { in.readBytes(packedValue, 0, packedValue.length); } catch (EOFException eofe) { assert countLeft == -1; return false; } docID = in.readInt(); if (singleValuePerDoc == false) { if (longOrds) { ord = in.readLong(); } else { ord = in.readInt(); } } else { ord = docID; } return true; }
@Override public final int readInt() throws IOException { try { return guard.getInt(curBuf); } catch (BufferUnderflowException e) { return super.readInt(); } catch (NullPointerException npe) { throw new AlreadyClosedException("Already closed: " + this); } }
/** Load metadata from the given {@link IndexInput}. * @see DirectMonotonicReader#getInstance(Meta, RandomAccessInput) */ public static Meta loadMeta(IndexInput metaIn, long numValues, int blockShift) throws IOException { Meta meta = new Meta(numValues, blockShift); for (int i = 0; i < meta.numBlocks; ++i) { meta.mins[i] = metaIn.readLong(); meta.avgs[i] = Float.intBitsToFloat(metaIn.readInt()); meta.offsets[i] = metaIn.readLong(); meta.bpvs[i] = metaIn.readByte(); } return meta; }
private void readFields(IndexInput meta, FieldInfos infos) throws IOException { for (int fieldNumber = meta.readInt(); fieldNumber != -1; fieldNumber = meta.readInt()) { FieldInfo info = infos.fieldInfo(fieldNumber); if (info == null) { throw new CorruptIndexException("Invalid field number: " + fieldNumber, meta); } else if (!info.hasNorms()) { throw new CorruptIndexException("Invalid field: " + info.name, meta); } NormsEntry entry = new NormsEntry(); entry.docsWithFieldOffset = meta.readLong(); entry.docsWithFieldLength = meta.readLong(); entry.numDocsWithField = meta.readInt(); entry.bytesPerNorm = meta.readByte(); switch (entry.bytesPerNorm) { case 0: case 1: case 2: case 4: case 8: break; default: throw new CorruptIndexException("Invalid bytesPerValue: " + entry.bytesPerNorm + ", field: " + info.name, meta); } entry.normsOffset = meta.readLong(); norms.put(info.number, entry); } }
break; case 4: rawValue = in.readInt(); break; case 5: rawValue = ((long)in.readInt() << 8) | (in.readByte() & 0xFFL); break; case 6: rawValue = ((long)in.readInt() << 16) | (in.readShort() & 0xFFFFL); break; case 7: rawValue = ((long)in.readInt() << 24) | ((in.readShort() & 0xFFFFL) << 8) | (in.readByte() & 0xFFL); break; case 8:
@Override public void markOrds(long count, LongBitSet ordBitSet) throws IOException { if (countLeft < count) { throw new IllegalStateException("only " + countLeft + " points remain, but " + count + " were requested"); } long fp = in.getFilePointer() + packedValue.length; if (singleValuePerDoc == false) { fp += Integer.BYTES; } for(long i=0;i<count;i++) { in.seek(fp); long ord; if (longOrds) { ord = in.readLong(); } else { ord = in.readInt(); } assert ordBitSet.get(ord) == false: "ord=" + ord + " i=" + i + " was seen twice from " + this; ordBitSet.set(ord); fp += bytesPerDoc; } }
private static void validateFooter(IndexInput in) throws IOException { long remaining = in.length() - in.getFilePointer(); long expected = footerLength(); if (remaining < expected) { throw new CorruptIndexException("misplaced codec footer (file truncated?): remaining=" + remaining + ", expected=" + expected + ", fp=" + in.getFilePointer(), in); } else if (remaining > expected) { throw new CorruptIndexException("misplaced codec footer (file extended?): remaining=" + remaining + ", expected=" + expected + ", fp=" + in.getFilePointer(), in); } final int magic = in.readInt(); if (magic != FOOTER_MAGIC) { throw new CorruptIndexException("codec footer mismatch (file truncated?): actual footer=" + magic + " vs expected footer=" + FOOTER_MAGIC, in); } final int algorithmID = in.readInt(); if (algorithmID != 0) { throw new CorruptIndexException("codec footer mismatch: unknown algorithmID: " + algorithmID, in); } }
/** Retrieves the full index header from the provided {@link IndexInput}. * This throws {@link CorruptIndexException} if this file does * not appear to be an index file. */ public static byte[] readIndexHeader(IndexInput in) throws IOException { in.seek(0); final int actualHeader = in.readInt(); if (actualHeader != CODEC_MAGIC) { throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC, in); } String codec = in.readString(); in.readInt(); in.seek(in.getFilePointer() + StringHelper.ID_LENGTH); int suffixLength = in.readByte() & 0xFF; byte[] bytes = new byte[headerLength(codec) + StringHelper.ID_LENGTH + 1 + suffixLength]; in.seek(0); in.readBytes(bytes, 0, bytes.length); return bytes; }
for (int i = 0; i < numBlocks; ++i) { minValues[i] = in.readZLong(); averages[i] = Float.intBitsToFloat(in.readInt()); final int bitsPerValue = in.readVInt(); sumBPV += bitsPerValue;
/** * Reads the state from a given file and compares the expected version against the actual version of * the state. */ public final T read(NamedXContentRegistry namedXContentRegistry, Path file) throws IOException { try (Directory dir = newDirectory(file.getParent())) { try (IndexInput indexInput = dir.openInput(file.getFileName().toString(), IOContext.DEFAULT)) { // We checksum the entire file before we even go and parse it. If it's corrupted we barf right here. CodecUtil.checksumEntireFile(indexInput); CodecUtil.checkHeader(indexInput, STATE_FILE_CODEC, MIN_COMPATIBLE_STATE_FILE_VERSION, STATE_FILE_VERSION); final XContentType xContentType = XContentType.values()[indexInput.readInt()]; if (xContentType != FORMAT) { throw new IllegalStateException("expected state in " + file + " to be " + FORMAT + " format but was " + xContentType); } long filePointer = indexInput.getFilePointer(); long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer; try (IndexInput slice = indexInput.slice("state_xcontent", filePointer, contentSize)) { try (XContentParser parser = XContentFactory.xContent(FORMAT) .createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, new InputStreamIndexInput(slice, contentSize))) { return fromXContent(parser); } } } catch(CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) { // we trick this into a dedicated exception with the original stacktrace throw new CorruptStateException(ex); } } }
charsPerTerm[i] = Float.intBitsToFloat(vectorsStream.readInt());
@Override public final int readInt() throws IOException { if (4 <= (bufferLength-bufferPosition)) { return ((buffer[bufferPosition++] & 0xFF) << 24) | ((buffer[bufferPosition++] & 0xFF) << 16) | ((buffer[bufferPosition++] & 0xFF) << 8) | (buffer[bufferPosition++] & 0xFF); } else { return super.readInt(); } }
@Override public int readInt(long pos) throws IOException { slice.seek(pos); return slice.readInt(); }
/** Load metadata from the given {@link IndexInput}. * @see DirectMonotonicReader#getInstance(Meta, RandomAccessInput) */ public static Meta loadMeta(IndexInput metaIn, long numValues, int blockShift) throws IOException { Meta meta = new Meta(numValues, blockShift); for (int i = 0; i < meta.numBlocks; ++i) { meta.mins[i] = metaIn.readLong(); meta.avgs[i] = Float.intBitsToFloat(metaIn.readInt()); meta.offsets[i] = metaIn.readLong(); meta.bpvs[i] = metaIn.readByte(); } return meta; }