當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexOutput.getFilePointer方法代碼示例

本文整理匯總了Java中org.apache.lucene.store.IndexOutput.getFilePointer方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexOutput.getFilePointer方法的具體用法?Java IndexOutput.getFilePointer怎麽用?Java IndexOutput.getFilePointer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.store.IndexOutput的用法示例。


在下文中一共展示了IndexOutput.getFilePointer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLargeWrites

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
/** This test that writes larger than the size of the buffer output
 * will correctly increment the file pointer.
 */
public void testLargeWrites() throws IOException {
    IndexOutput os = dir.createOutput("testBufferStart.txt", newIOContext(random()));

    byte[] largeBuf = new byte[2048];
    for (int i=0; i<largeBuf.length; i++) {
        largeBuf[i] = (byte) (Math.random() * 256);
    }

    long currentPos = os.getFilePointer();
    os.writeBytes(largeBuf, largeBuf.length);

    try {
        assertEquals(currentPos + largeBuf.length, os.getFilePointer());
    } finally {
        os.close();
    }

}
 
開發者ID:europeana,項目名稱:search,代碼行數:22,代碼來源:TestCompoundFile.java

示例2: testSingleValue

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
public void testSingleValue() throws Exception {
  for (int bitsPerValue = 1; bitsPerValue <= 64; ++bitsPerValue) {
    Directory dir = newDirectory();
    IndexOutput out = dir.createOutput("out", newIOContext(random()));
    PackedInts.Writer w = PackedInts.getWriter(out, 1, bitsPerValue, PackedInts.DEFAULT);
    long value = 17L & PackedInts.maxValue(bitsPerValue);
    w.add(value);
    w.finish();
    final long end = out.getFilePointer();
    out.close();

    IndexInput in = dir.openInput("out", newIOContext(random()));
    Reader reader = PackedInts.getReader(in);
    String msg = "Impl=" + w.getClass().getSimpleName() + ", bitsPerValue=" + bitsPerValue;
    assertEquals(msg, 1, reader.size());
    assertEquals(msg, value, reader.get(0));
    assertEquals(msg, end, in.getFilePointer());
    in.close();

    dir.close();
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:23,代碼來源:TestPackedInts.java

示例3: testMonotonicBlockPackedReaderWriter

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
public void testMonotonicBlockPackedReaderWriter() throws IOException {
  final int iters = atLeast(2);
  for (int iter = 0; iter < iters; ++iter) {
    final int blockSize = 1 << TestUtil.nextInt(random(), 6, 18);
    final int valueCount = random().nextInt(1 << 18);
    final long[] values = new long[valueCount];
    if (valueCount > 0) {
      values[0] = random().nextBoolean() ? random().nextInt(10) : random().nextInt(Integer.MAX_VALUE);
      int maxDelta = random().nextInt(64);
      for (int i = 1; i < valueCount; ++i) {
        if (random().nextDouble() < 0.1d) {
          maxDelta = random().nextInt(64);
        }
        values[i] = Math.max(0, values[i-1] + TestUtil.nextInt(random(), -16, maxDelta));
      }
    }

    final Directory dir = newDirectory();
    final IndexOutput out = dir.createOutput("out.bin", IOContext.DEFAULT);
    final MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(out, blockSize);
    for (int i = 0; i < valueCount; ++i) {
      assertEquals(i, writer.ord());
      writer.add(values[i]);
    }
    assertEquals(valueCount, writer.ord());
    writer.finish();
    assertEquals(valueCount, writer.ord());
    final long fp = out.getFilePointer();
    out.close();

    final IndexInput in = dir.openInput("out.bin", IOContext.DEFAULT);
    final MonotonicBlockPackedReader reader = MonotonicBlockPackedReader.of(in, PackedInts.VERSION_CURRENT, blockSize, valueCount, random().nextBoolean());
    assertEquals(fp, in.getFilePointer());
    for (int i = 0; i < valueCount; ++i) {
      assertEquals("i=" +i, values[i], reader.get(i));
    }
    in.close();
    dir.close();
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:41,代碼來源:TestPackedInts.java


注:本文中的org.apache.lucene.store.IndexOutput.getFilePointer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。