當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。