Java Code Examples for org.apache.lucene.store.DataInput#readInt()

The following examples show how to use org.apache.lucene.store.DataInput#readInt() . 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: FuzzySet.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static FuzzySet deserialize(DataInput in) throws IOException
{
  int version=in.readInt();
  if (version == VERSION_SPI) {
    in.readString();
  }
  final HashFunction hashFunction = hashFunctionForVersion(version);
  int bloomSize=in.readInt();
  int numLongs=in.readInt();
  long[]longs=new long[numLongs];
  for (int i = 0; i < numLongs; i++) {
    longs[i]=in.readLong();
  }
  FixedBitSet bits = new FixedBitSet(longs,bloomSize+1);
  return new FuzzySet(bits,bloomSize,hashFunction);
}
 
Example 2
Source File: CompressingStoredFieldsReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 3
Source File: CodecUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example 4
Source File: SortedNumericSortField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public SortField readSortField(DataInput in) throws IOException {
  SortedNumericSortField sf = new SortedNumericSortField(in.readString(), readType(in), in.readInt() == 1, readSelectorType(in));
  if (in.readInt() == 1) {
    switch (sf.type) {
      case INT:
        sf.setMissingValue(in.readInt());
        break;
      case LONG:
        sf.setMissingValue(in.readLong());
        break;
      case FLOAT:
        sf.setMissingValue(NumericUtils.sortableIntToFloat(in.readInt()));
        break;
      case DOUBLE:
        sf.setMissingValue(NumericUtils.sortableLongToDouble(in.readLong()));
        break;
      default:
        throw new AssertionError();
    }
  }
  return sf;
}
 
Example 5
Source File: BloomFilter.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static BloomFilter deserialize(DataInput in) throws IOException {
    int version = in.readInt(); // we do nothing with this now..., defaults to 0
    int numLongs = in.readInt();
    long[] data = new long[numLongs];
    for (int i = 0; i < numLongs; i++) {
        data[i] = in.readLong();
    }
    int numberOfHashFunctions = in.readInt();
    int hashType = in.readInt();
    return new BloomFilter(new BitArray(data), numberOfHashFunctions, Hashing.fromType(hashType));
}
 
Example 6
Source File: SortedSetSortField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public SortField readSortField(DataInput in) throws IOException {
  SortField sf = new SortedSetSortField(in.readString(), in.readInt() == 1, readSelectorType(in));
  int missingValue = in.readInt();
  if (missingValue == 1) {
    sf.setMissingValue(SortField.STRING_FIRST);
  }
  else if (missingValue == 2) {
    sf.setMissingValue(SortField.STRING_LAST);
  }
  return sf;
}
 
Example 7
Source File: SortedSetSortField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static SortedSetSelector.Type readSelectorType(DataInput in) throws IOException {
  int type = in.readInt();
  if (type >= SortedSetSelector.Type.values().length) {
    throw new IllegalArgumentException("Cannot deserialize SortedSetSortField: unknown selector type " + type);
  }
  return SortedSetSelector.Type.values()[type];
}
 
Example 8
Source File: SortField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public SortField readSortField(DataInput in) throws IOException {
  SortField sf = new SortField(in.readString(), readType(in), in.readInt() == 1);
  if (in.readInt() == 1) {
    // missing object
    switch (sf.type) {
      case STRING:
        int missingString = in.readInt();
        if (missingString == 1) {
          sf.setMissingValue(STRING_FIRST);
        }
        else {
          sf.setMissingValue(STRING_LAST);
        }
        break;
      case INT:
        sf.setMissingValue(in.readInt());
        break;
      case LONG:
        sf.setMissingValue(in.readLong());
        break;
      case FLOAT:
        sf.setMissingValue(NumericUtils.sortableIntToFloat(in.readInt()));
        break;
      case DOUBLE:
        sf.setMissingValue(NumericUtils.sortableLongToDouble(in.readLong()));
        break;
      default:
        throw new IllegalArgumentException("Cannot deserialize sort of type " + sf.type);
    }
  }
  return sf;
}
 
Example 9
Source File: SortedNumericSortField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static SortedNumericSelector.Type readSelectorType(DataInput in) throws IOException {
  int selectorType = in.readInt();
  if (selectorType >= SortedNumericSelector.Type.values().length) {
    throw new IllegalArgumentException("Can't deserialize SortedNumericSortField - unknown selector type " + selectorType);
  }
  return SortedNumericSelector.Type.values()[selectorType];
}
 
Example 10
Source File: Checkpoint.java    From crate with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: Checkpoint.java    From crate with Apache License 2.0 5 votes vote down vote up
static Checkpoint readCheckpointV6_0_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 = SequenceNumbers.UNASSIGNED_SEQ_NO;
    return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
}
 
Example 12
Source File: Checkpoint.java    From crate with Apache License 2.0 5 votes vote down vote up
static Checkpoint readCheckpointV5_0_0(final DataInput in) throws IOException {
    final long offset = in.readLong();
    final int numOps = in.readInt();
    final long generation = in.readLong();
    final long minSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
    final long maxSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
    final long globalCheckpoint = SequenceNumbers.UNASSIGNED_SEQ_NO;
    final long minTranslogGeneration = -1;
    final long trimmedAboveSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
    return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
}
 
Example 13
Source File: Checkpoint.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
Checkpoint(DataInput in) throws IOException {
    offset = in.readLong();
    numOps = in.readInt();
    generation = in.readLong();
}
 
Example 14
Source File: CodecUtil.java    From lucene-solr with Apache License 2.0 3 votes vote down vote up
/**
 * Reads and validates a header previously written with 
 * {@link #writeHeader(DataOutput, String, int)}.
 * <p>
 * When reading a file, supply the expected <code>codec</code> and
 * an expected version range (<code>minVersion to maxVersion</code>).
 * 
 * @param in Input stream, positioned at the point where the
 *        header was previously written. Typically this is located
 *        at the beginning of the file.
 * @param codec The expected codec name.
 * @param minVersion The minimum supported expected version number.
 * @param maxVersion The maximum supported expected version number.
 * @return The actual version found, when a valid header is found 
 *         that matches <code>codec</code>, with an actual version 
 *         where {@code minVersion <= actual <= maxVersion}.
 *         Otherwise an exception is thrown.
 * @throws CorruptIndexException If the first four bytes are not
 *         {@link #CODEC_MAGIC}, or if the actual codec found is
 *         not <code>codec</code>.
 * @throws IndexFormatTooOldException If the actual version is less 
 *         than <code>minVersion</code>.
 * @throws IndexFormatTooNewException If the actual version is greater 
 *         than <code>maxVersion</code>.
 * @throws IOException If there is an I/O error reading from the underlying medium.
 * @see #writeHeader(DataOutput, String, int)
 */
public static int checkHeader(DataInput in, String codec, int minVersion, int maxVersion) throws IOException {
  // Safety to guard against reading a bogus string:
  final int actualHeader = in.readInt();
  if (actualHeader != CODEC_MAGIC) {
    throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC, in);
  }
  return checkHeaderNoMagic(in, codec, minVersion, maxVersion);
}