Java Code Examples for org.apache.lucene.store.ChecksumIndexInput#readByte()

The following examples show how to use org.apache.lucene.store.ChecksumIndexInput#readByte() . These examples are extracted from open source projects. 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
private void readFields(ChecksumIndexInput 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);
    }
    byte type = meta.readByte();
    if (type == Lucene80DocValuesFormat.NUMERIC) {
      numerics.put(info.name, readNumeric(meta));
    } else if (type == Lucene80DocValuesFormat.BINARY) {
      binaries.put(info.name, readBinary(meta));
    } else if (type == Lucene80DocValuesFormat.SORTED) {
      sorted.put(info.name, readSorted(meta));
    } else if (type == Lucene80DocValuesFormat.SORTED_SET) {
      sortedSets.put(info.name, readSortedSet(meta));
    } else if (type == Lucene80DocValuesFormat.SORTED_NUMERIC) {
      sortedNumerics.put(info.name, readSortedNumeric(meta));
    } else {
      throw new CorruptIndexException("invalid type: " + type, meta);
    }
  }
}
 
Example 2
Source Project: lucene-solr   File: TestCodecUtil.java    License: Apache License 2.0 6 votes vote down vote up
public void testCheckFooterValidPastFooter() throws Exception {
  ByteBuffersDataOutput out = new ByteBuffersDataOutput();
  IndexOutput output = new ByteBuffersIndexOutput(out, "temp", "temp");
  CodecUtil.writeHeader(output, "FooBar", 5);
  output.writeString("this is the data");
  CodecUtil.writeFooter(output);
  output.close();
  
  ChecksumIndexInput input = new BufferedChecksumIndexInput(new ByteBuffersIndexInput(out.toDataInput(), "temp"));
  CodecUtil.checkHeader(input, "FooBar", 5, 5);
  assertEquals("this is the data", input.readString());
  // bogusly read a byte too far (can happen)
  input.readByte();
  Exception mine = new RuntimeException("fake exception");
  CorruptIndexException expected = expectThrows(CorruptIndexException.class, () -> {
    CodecUtil.checkFooter(input, mine);
  });
  assertTrue(expected.getMessage().contains("checksum status indeterminate"));
  Throwable suppressed[] = expected.getSuppressed();
  assertEquals(1, suppressed.length);
  assertEquals("fake exception", suppressed[0].getMessage());
  input.close();
}
 
Example 3
private void readNumeric(ChecksumIndexInput meta, NumericEntry entry) throws IOException {
  entry.docsWithFieldOffset = meta.readLong();
  entry.docsWithFieldLength = meta.readLong();
  entry.jumpTableEntryCount = meta.readShort();
  entry.denseRankPower = meta.readByte();
  entry.numValues = meta.readLong();
  int tableSize = meta.readInt();
  if (tableSize > 256) {
    throw new CorruptIndexException("invalid table size: " + tableSize, meta);
  }
  if (tableSize >= 0) {
    entry.table = new long[tableSize];
    ramBytesUsed += RamUsageEstimator.sizeOf(entry.table);
    for (int i = 0; i < tableSize; ++i) {
      entry.table[i] = meta.readLong();
    }
  }
  if (tableSize < -1) {
    entry.blockShift = -2 - tableSize;
  } else {
    entry.blockShift = -1;
  }
  entry.bitsPerValue = meta.readByte();
  entry.minValue = meta.readLong();
  entry.gcd = meta.readLong();
  entry.valuesOffset = meta.readLong();
  entry.valuesLength = meta.readLong();
  entry.valueJumpTableOffset = meta.readLong();
}
 
Example 4
private BinaryEntry readBinary(ChecksumIndexInput meta) throws IOException {
  BinaryEntry entry = new BinaryEntry();
  entry.dataOffset = meta.readLong();
  entry.dataLength = meta.readLong();
  entry.docsWithFieldOffset = meta.readLong();
  entry.docsWithFieldLength = meta.readLong();
  entry.jumpTableEntryCount = meta.readShort();
  entry.denseRankPower = meta.readByte();
  entry.numDocsWithField = meta.readInt();
  entry.minLength = meta.readInt();
  entry.maxLength = meta.readInt();
  if ((version >= Lucene80DocValuesFormat.VERSION_BIN_COMPRESSED && entry.numDocsWithField > 0) ||  entry.minLength < entry.maxLength) {
    entry.addressesOffset = meta.readLong();

    // Old count of uncompressed addresses 
    long numAddresses = entry.numDocsWithField + 1L;
    // New count of compressed addresses - the number of compresseed blocks
    if (version >= Lucene80DocValuesFormat.VERSION_BIN_COMPRESSED) {
      entry.numCompressedChunks = meta.readVInt();
      entry.docsPerChunkShift = meta.readVInt();
      entry.maxUncompressedChunkSize = meta.readVInt();
      numAddresses = entry.numCompressedChunks;
    }      
    
    final int blockShift = meta.readVInt();
    entry.addressesMeta = DirectMonotonicReader.loadMeta(meta, numAddresses, blockShift);
    ramBytesUsed += entry.addressesMeta.ramBytesUsed();
    entry.addressesLength = meta.readLong();
  }
  return entry;
}
 
Example 5
private SortedEntry readSorted(ChecksumIndexInput meta) throws IOException {
  SortedEntry entry = new SortedEntry();
  entry.docsWithFieldOffset = meta.readLong();
  entry.docsWithFieldLength = meta.readLong();
  entry.jumpTableEntryCount = meta.readShort();
  entry.denseRankPower = meta.readByte();
  entry.numDocsWithField = meta.readInt();
  entry.bitsPerValue = meta.readByte();
  entry.ordsOffset = meta.readLong();
  entry.ordsLength = meta.readLong();
  readTermDict(meta, entry);
  return entry;
}
 
Example 6
private SortedSetEntry readSortedSet(ChecksumIndexInput meta) throws IOException {
  SortedSetEntry entry = new SortedSetEntry();
  byte multiValued = meta.readByte();
  switch (multiValued) {
    case 0: // singlevalued
      entry.singleValueEntry = readSorted(meta);
      return entry;
    case 1: // multivalued
      break;
    default:
      throw new CorruptIndexException("Invalid multiValued flag: " + multiValued, meta);
  }
  entry.docsWithFieldOffset = meta.readLong();
  entry.docsWithFieldLength = meta.readLong();
  entry.jumpTableEntryCount = meta.readShort();
  entry.denseRankPower = meta.readByte();
  entry.bitsPerValue = meta.readByte();
  entry.ordsOffset = meta.readLong();
  entry.ordsLength = meta.readLong();
  entry.numDocsWithField = meta.readInt();
  entry.addressesOffset = meta.readLong();
  final int blockShift = meta.readVInt();
  entry.addressesMeta = DirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
  ramBytesUsed += entry.addressesMeta.ramBytesUsed();
  entry.addressesLength = meta.readLong();
  readTermDict(meta, entry);
  return entry;
}