当前位置: 首页>>代码示例>>Java>>正文


Java IndexInput.readBytes方法代码示例

本文整理汇总了Java中org.apache.lucene.store.IndexInput.readBytes方法的典型用法代码示例。如果您正苦于以下问题:Java IndexInput.readBytes方法的具体用法?Java IndexInput.readBytes怎么用?Java IndexInput.readBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.store.IndexInput的用法示例。


在下文中一共展示了IndexInput.readBytes方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: corruptFile

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private void corruptFile(Directory dir, String fileIn, String fileOut) throws IOException {
    IndexInput input = dir.openInput(fileIn, IOContext.READONCE);
    IndexOutput output = dir.createOutput(fileOut, IOContext.DEFAULT);
    long len = input.length();
    byte[] b = new byte[1024];
    long broken = randomInt((int) len-1);
    long pos = 0;
    while (pos < len) {
        int min = (int) Math.min(input.length() - pos, b.length);
        input.readBytes(b, 0, min);
        if (broken >= pos && broken < pos + min) {
            // Flip one byte
            int flipPos = (int) (broken - pos);
            b[flipPos] = (byte) (b[flipPos] ^ 42);
        }
        output.writeBytes(b, min);
        pos += min;
    }
    IOUtils.close(input, output);

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:StoreTests.java

示例2: loadByteField

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private NumericDocValues loadByteField(FieldInfo field, IndexInput input) throws IOException {
  CodecUtil.checkHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME,
                               Lucene40DocValuesFormat.INTS_VERSION_START,
                               Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
  int valueSize = input.readInt();
  if (valueSize != 1) {
    throw new CorruptIndexException("invalid valueSize: " + valueSize);
  }
  int maxDoc = state.segmentInfo.getDocCount();
  final byte values[] = new byte[maxDoc];
  input.readBytes(values, 0, values.length);
  ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
  return new NumericDocValues() {
    @Override
    public long get(int docID) {
      return values[docID];
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:Lucene40DocValuesReader.java

示例3: getVariableBinary

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private BinaryDocValues getVariableBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
  final IndexInput data = this.data.clone();
  
  final MonotonicBlockPackedReader addresses = getAddressInstance(data, field, bytes);

  return new LongBinaryDocValues() {
    final BytesRef term = new BytesRef(Math.max(0, bytes.maxLength));

    @Override
    public BytesRef get(long id) {
      long startAddress = bytes.offset + (id == 0 ? 0 : addresses.get(id-1));
      long endAddress = bytes.offset + addresses.get(id);
      int length = (int) (endAddress - startAddress);
      try {
        data.seek(startAddress);
        data.readBytes(term.bytes, 0, length);
        term.length = length;
        return term;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:Lucene45DocValuesProducer.java

示例4: getVariableBinary

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private BinaryDocValues getVariableBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
  final IndexInput data = this.data.clone();
  
  final MonotonicBlockPackedReader addresses = getAddressInstance(data, field, bytes);

  return new LongBinaryDocValues() {
    final BytesRef term = new BytesRef(Math.max(0, bytes.maxLength));
    
    @Override
    public BytesRef get(long id) {
      long startAddress = bytes.offset + addresses.get(id);
      long endAddress = bytes.offset + addresses.get(id+1);
      int length = (int) (endAddress - startAddress);
      try {
        data.seek(startAddress);
        data.readBytes(term.bytes, 0, length);
        term.length = length;
        return term;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:Lucene49DocValuesProducer.java

示例5: getFixedBinary

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private BinaryDocValues getFixedBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
  final IndexInput data = this.data.slice("fixed-binary", bytes.offset, bytes.count * bytes.maxLength);

  final BytesRef term = new BytesRef(bytes.maxLength);
  final byte[] buffer = term.bytes;
  final int length = term.length = bytes.maxLength;
  
  return new LongBinaryDocValues() {
    @Override
    public BytesRef get(long id) {
      try {
        data.seek(id * length);
        data.readBytes(buffer, 0, buffer.length);
        return term;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:Lucene410DocValuesProducer.java

示例6: getVariableBinary

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private BinaryDocValues getVariableBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
  final MonotonicBlockPackedReader addresses = getAddressInstance(field, bytes);

  final IndexInput data = this.data.slice("var-binary", bytes.offset, bytes.addressesOffset - bytes.offset);
  final BytesRef term = new BytesRef(Math.max(0, bytes.maxLength));
  final byte buffer[] = term.bytes;
  
  return new LongBinaryDocValues() {      
    @Override
    public BytesRef get(long id) {
      long startAddress = addresses.get(id);
      long endAddress = addresses.get(id+1);
      int length = (int) (endAddress - startAddress);
      try {
        data.seek(startAddress);
        data.readBytes(buffer, 0, length);
        term.length = length;
        return term;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:Lucene410DocValuesProducer.java

示例7: copy

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
/** Read this many bytes from in */
public void copy(IndexInput in, long byteCount) throws IOException {
  while (byteCount > 0) {
    int left = blockSize - upto;
    if (left == 0) {
      if (currentBlock != null) {
        addBlock(currentBlock);
      }
      currentBlock = new byte[blockSize];
      upto = 0;
      left = blockSize;
    }
    if (left < byteCount) {
      in.readBytes(currentBlock, upto, left, false);
      upto = blockSize;
      byteCount -= left;
    } else {
      in.readBytes(currentBlock, upto, (int) byteCount, false);
      upto += byteCount;
      break;
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:PagedBytes.java

示例8: readBytesRef

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private static BytesRef readBytesRef(IndexInput in) throws IOException {
  BytesRef bytes = new BytesRef();
  bytes.length = in.readVInt();
  bytes.bytes = new byte[bytes.length];
  in.readBytes(bytes.bytes, 0, bytes.length);
  return bytes;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:BlockTreeTermsReader.java

示例9: readHeader

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
@Override
protected void readHeader(IndexInput in) throws IOException {
    byte[] header = new byte[LZFCompressor.LUCENE_HEADER.length];
    in.readBytes(header, 0, header.length, false);
    if (!Arrays.equals(header, LZFCompressor.LUCENE_HEADER)) {
        throw new IOException("wrong lzf compressed header [" + Arrays.toString(header) + "]");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:LZFCompressedIndexInput.java

示例10: randomReadAndSlice

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
private byte[] randomReadAndSlice(IndexInput indexInput, int length) throws IOException {
    int readPos = (int) indexInput.getFilePointer();
    byte[] output = new byte[length];
    while (readPos < length) {
        switch (randomIntBetween(0, 3)) {
            case 0:
                // Read by one byte at a time
                output[readPos++] = indexInput.readByte();
                break;
            case 1:
                // Read several bytes into target
                int len = randomIntBetween(1, length - readPos);
                indexInput.readBytes(output, readPos, len);
                readPos += len;
                break;
            case 2:
                // Read several bytes into 0-offset target
                len = randomIntBetween(1, length - readPos);
                byte[] temp = new byte[len];
                indexInput.readBytes(temp, 0, len);
                System.arraycopy(temp, 0, output, readPos, len);
                readPos += len;
                break;
            case 3:
                // Read using slice
                len = randomIntBetween(1, length - readPos);
                IndexInput slice = indexInput.slice("slice (" + readPos + ", " + len + ") of " + indexInput.toString(), readPos, len);
                temp = randomReadAndSlice(slice, len);
                // assert that position in the original input didn't change
                assertEquals(readPos, indexInput.getFilePointer());
                System.arraycopy(temp, 0, output, readPos, len);
                readPos += len;
                indexInput.seek(readPos);
                assertEquals(readPos, indexInput.getFilePointer());
                break;
            default:
                fail();
        }
        assertEquals(readPos, indexInput.getFilePointer());
    }
    return output;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:43,代码来源:ByteArrayIndexInputTests.java

示例11: readBits

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
/** Read as a bit set */
private void readBits(IndexInput input) throws IOException {
  count = input.readInt();        // read count
  bits = new byte[getNumBytes(size)];     // allocate bits
  input.readBytes(bits, 0, bits.length);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:BitVector.java

示例12: SkipBuffer

import org.apache.lucene.store.IndexInput; //导入方法依赖的package包/类
SkipBuffer(IndexInput input, int length) throws IOException {
  super("SkipBuffer on " + input);
  data = new byte[length];
  pointer = input.getFilePointer();
  input.readBytes(data, 0, length);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:MultiLevelSkipListReader.java


注:本文中的org.apache.lucene.store.IndexInput.readBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。