Java Code Examples for org.apache.lucene.store.IndexInput#readLong()

The following examples show how to use org.apache.lucene.store.IndexInput#readLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompressedIndexInput.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public CompressedIndexInput(IndexInput in) throws IOException {
    super("compressed(" + in.toString() + ")");
    this.in = in;
    readHeader(in);
    this.version = in.readInt();
    long metaDataPosition = in.readLong();
    long headerLength = in.getFilePointer();
    in.seek(metaDataPosition);
    this.totalUncompressedLength = in.readVLong();
    int size = in.readVInt();
    offsets = BigArrays.NON_RECYCLING_INSTANCE.newLongArray(size);
    for (int i = 0; i < size; i++) {
        offsets.set(i, in.readVLong());
    }
    this.currentOffsetIdx = -1;
    this.currentUncompressedChunkPointer = 0;
    in.seek(headerLength);
}
 
Example 2
Source File: Lucene80NormsProducer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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.jumpTableEntryCount = meta.readShort();
    entry.denseRankPower = meta.readByte();
    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);
  }
}
 
Example 3
Source File: DocIdsWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static void readInts24(IndexInput in, int count, int[] docIDs) throws IOException {
  int i;
  for (i = 0; i < count - 7; i += 8) {
    long l1 = in.readLong();
    long l2 = in.readLong();
    long l3 = in.readLong();
    docIDs[i] =  (int) (l1 >>> 40);
    docIDs[i+1] = (int) (l1 >>> 16) & 0xffffff;
    docIDs[i+2] = (int) (((l1 & 0xffff) << 8) | (l2 >>> 56));
    docIDs[i+3] = (int) (l2 >>> 32) & 0xffffff;
    docIDs[i+4] = (int) (l2 >>> 8) & 0xffffff;
    docIDs[i+5] = (int) (((l2 & 0xff) << 16) | (l3 >>> 48));
    docIDs[i+6] = (int) (l3 >>> 24) & 0xffffff;
    docIDs[i+7] = (int) l3 & 0xffffff;
  }
  for (; i < count; ++i) {
    docIDs[i] = (Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte());
  }
}
 
Example 4
Source File: DocIdsWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static void readInts24(IndexInput in, int count, IntersectVisitor visitor) throws IOException {
  int i;
  for (i = 0; i < count - 7; i += 8) {
    long l1 = in.readLong();
    long l2 = in.readLong();
    long l3 = in.readLong();
    visitor.visit((int) (l1 >>> 40));
    visitor.visit((int) (l1 >>> 16) & 0xffffff);
    visitor.visit((int) (((l1 & 0xffff) << 8) | (l2 >>> 56)));
    visitor.visit((int) (l2 >>> 32) & 0xffffff);
    visitor.visit((int) (l2 >>> 8) & 0xffffff);
    visitor.visit((int) (((l2 & 0xff) << 16) | (l3 >>> 48)));
    visitor.visit((int) (l3 >>> 24) & 0xffffff);
    visitor.visit((int) l3 & 0xffffff);
  }
  for (; i < count; ++i) {
    visitor.visit((Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte()));
  }
}
 
Example 5
Source File: CacheIndexInputTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public static void readRandomDataLong(IndexInput baseInput, IndexInput testInput, Random random, int sampleSize)
    throws IOException {
  assertEquals(baseInput.length(), testInput.length());
  int fileLength = (int) baseInput.length();
  for (int i = 0; i < sampleSize; i++) {
    int position = random.nextInt(fileLength - 8);
    baseInput.seek(position);
    long i1 = baseInput.readLong();
    testInput.seek(position);
    long i2 = testInput.readLong();
    assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2);
  }
}
 
Example 6
Source File: DirectPacked64SingleBlockReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public long get(int index) {
  final int blockOffset = index / valuesPerBlock;
  final long skip = ((long) blockOffset) << 3;
  try {
    IndexInput indexInput = in.get();
    indexInput.seek(startPointer + skip);

    long block = indexInput.readLong();
    final int offsetInBlock = index % valuesPerBlock;
    return (block >>> (offsetInBlock * bitsPerValue)) & mask;
  } catch (IOException e) {
    throw new IllegalStateException("failed", e);
  }
}
 
Example 7
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
/** Seek {@code input} to the directory offset. */
protected void seekDir(IndexInput input, long dirOffset)
    throws IOException {
  if (version >= BlockTreeTermsWriter.TERMS_INDEX_VERSION_APPEND_ONLY) {
    input.seek(input.length() - 8);
    dirOffset = input.readLong();
  }
  input.seek(dirOffset);
}
 
Example 8
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
/** Reads index file header. */
protected int readIndexHeader(IndexInput input) throws IOException {
  int version = CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_INDEX_CODEC_NAME,
                        BlockTreeTermsWriter.TERMS_INDEX_VERSION_START,
                        BlockTreeTermsWriter.TERMS_INDEX_VERSION_CURRENT);
  if (version < BlockTreeTermsWriter.TERMS_INDEX_VERSION_APPEND_ONLY) {
    indexDirOffset = input.readLong(); 
  }
  return version;
}
 
Example 9
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
/** Reads terms file header. */
protected int readHeader(IndexInput input) throws IOException {
  int version = CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_CODEC_NAME,
                        BlockTreeTermsWriter.TERMS_VERSION_START,
                        BlockTreeTermsWriter.TERMS_VERSION_CURRENT);
  if (version < BlockTreeTermsWriter.TERMS_VERSION_APPEND_ONLY) {
    dirOffset = input.readLong();
  }
  return version;
}
 
Example 10
Source File: DiskDocValuesProducer.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
static BinaryEntry readBinaryEntry(IndexInput meta) throws IOException {
  BinaryEntry entry = new BinaryEntry();
  entry.minLength = meta.readVInt();
  entry.maxLength = meta.readVInt();
  entry.count = meta.readVLong();
  entry.offset = meta.readLong();
  if (entry.minLength != entry.maxLength) {
    entry.addressesOffset = meta.readLong();
    entry.packedIntsVersion = meta.readVInt();
    entry.blockSize = meta.readVInt();
  }
  return entry;
}
 
Example 11
Source File: DiskDocValuesProducer.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
static NumericEntry readNumericEntry(IndexInput meta) throws IOException {
  NumericEntry entry = new NumericEntry();
  entry.packedIntsVersion = meta.readVInt();
  entry.offset = meta.readLong();
  entry.count = meta.readVLong();
  entry.blockSize = meta.readVInt();
  return entry;
}
 
Example 12
Source File: HdfsDirectoryResourceTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private void executeReads(HdfsDirectory dir, String name) throws IOException, InterruptedException {
  IndexInput input = dir.openInput(name, IOContext.READ);
  assertResourceCount(1);
  input.readLong();
  input.seek(0L);
  for (int i = 0; i < 2; i++) {
    readSeq(input.clone(), READ_SIZE);
    assertResourceCount(1 + i + 1);
  }
  input.close();
}
 
Example 13
Source File: DirectMonotonicReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example 14
Source File: CodecUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Reads CRC32 value as a 64-bit long from the input.
 * @throws CorruptIndexException if CRC is formatted incorrectly (wrong bits set)
 * @throws IOException if an i/o error occurs
 */
static long readCRC(IndexInput input) throws IOException {
  long value = input.readLong();
  if ((value & 0xFFFFFFFF00000000L) != 0) {
    throw new CorruptIndexException("Illegal CRC-32 checksum: " + value, input);
  }
  return value;
}
 
Example 15
Source File: GenericRecordReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private static boolean isValid(HdfsDirectory localDir, Directory remoteDir, String name) throws IOException {
  LastModified lastModified = (LastModified) remoteDir;
  long fileModified = lastModified.getFileModified(name);
  long fileLength = remoteDir.fileLength(name);

  if (localDir.fileExists(name)) {
    LOG.info("Cache file exists [{0}]", name);
    if (localDir.fileLength(name) == fileLength) {
      LOG.info("Cache file length matches [{0}]", name);
      String lastModFile = name + LASTMOD;
      if (localDir.fileExists(lastModFile) && localDir.fileLength(lastModFile) == 8) {
        LOG.info("Cache file last mod file exists [{0}]", name);
        IndexInput input = localDir.openInput(lastModFile, IOContext.DEFAULT);
        long lastMod = input.readLong();
        if (lastMod == fileModified) {
          LOG.info("Cache file last mod matches [{0}]", name);
          return true;
        } else {
          LOG.info("Cache file last mod does not match [{0}]", name);
        }
      } else {
        LOG.info("Cache file last mod file does not exist [{0}]", name);
      }
    } else {
      LOG.info("Cache file length does not match [{0}]", name);
    }
  } else {
    LOG.info("Cache file does not exist [{0}]", name);
  }
  return false;
}
 
Example 16
Source File: BlockTreeTermsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Seek {@code input} to the directory offset. */
private static void seekDir(IndexInput input) throws IOException {
  input.seek(input.length() - CodecUtil.footerLength() - 8);
  long offset = input.readLong();
  input.seek(offset);
}
 
Example 17
Source File: FixedGapTermsIndexReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void seekDir(IndexInput input) throws IOException {
  input.seek(input.length() - CodecUtil.footerLength() - 8);
  long dirOffset = input.readLong();
  input.seek(dirOffset);
}
 
Example 18
Source File: VariableGapTermsIndexReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void seekDir(IndexInput input) throws IOException {
  input.seek(input.length() - CodecUtil.footerLength() - 8);
  long dirOffset = input.readLong();
  input.seek(dirOffset);
}
 
Example 19
Source File: BlockTermsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void seekDir(IndexInput input) throws IOException {
  input.seek(input.length() - CodecUtil.footerLength() - 8);
  long dirOffset = input.readLong();
  input.seek(dirOffset);
}
 
Example 20
Source File: OrdsBlockTreeTermsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Seek {@code input} to the directory offset. */
private void seekDir(IndexInput input) throws IOException {
  input.seek(input.length() - CodecUtil.footerLength() - 8);
  long dirOffset = input.readLong();
  input.seek(dirOffset);
}