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


Java ByteArrayDataOutput.writeVInt方法代码示例

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


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

示例1: binaryValue

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
@Override
public BytesRef binaryValue() {
    try {
        CollectionUtils.sortAndDedup(bytesList);
        int size = bytesList.size();
        final byte[] bytes = new byte[totalSize + (size + 1) * 5];
        ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
        out.writeVInt(size);  // write total number of values
        for (int i = 0; i < size; i ++) {
            final byte[] value = bytesList.get(i);
            int valueLength = value.length;
            out.writeVInt(valueLength);
            out.writeBytes(value, 0, valueLength);
        }
        return new BytesRef(bytes, 0, out.getPosition());
    } catch (IOException e) {
        throw new ElasticsearchException("Failed to get binary value", e);
    }

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

示例2: beforeClass

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws IOException {
  Random random = random();
  INTS = new int[COUNT];
  LONGS = new long[COUNT];
  RANDOM_TEST_BYTES = new byte[COUNT * (5 + 4 + 9 + 8)];
  final ByteArrayDataOutput bdo = new ByteArrayDataOutput(RANDOM_TEST_BYTES);
  for (int i = 0; i < COUNT; i++) {
    final int i1 = INTS[i] = random.nextInt();
    bdo.writeVInt(i1);
    bdo.writeInt(i1);

    final long l1;
    if (rarely()) {
      // a long with lots of zeroes at the end
      l1 = LONGS[i] = TestUtil.nextLong(random, 0, Integer.MAX_VALUE) << 32;
    } else {
      l1 = LONGS[i] = TestUtil.nextLong(random, 0, Long.MAX_VALUE);
    }
    bdo.writeVLong(l1);
    bdo.writeLong(l1);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestIndexInput.java

示例3: binaryValue

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
@Override
public BytesRef binaryValue() {
    try {
        CollectionUtils.sortAndDedup(bytesList);
        final int size = bytesList.size();
        final byte[] bytes = new byte[totalSize + (size + 1) * 5];
        final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
        out.writeVInt(size); // write total number of values
        for (int i = 0; i < size; i++) {
            final byte[] value = bytesList.get(i);
            final int valueLength = value.length;
            out.writeVInt(valueLength);
            out.writeBytes(value, 0, valueLength);
        }
        return new BytesRef(bytes, 0, out.getPosition());
    } catch (final IOException e) {
        throw new ElasticsearchException("Failed to get binary value",
                e);
    }

}
 
开发者ID:sherlok,项目名称:sherlastic,代码行数:22,代码来源:SherlokFieldMapper.java

示例4: binaryValue

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
@Override
public BytesRef binaryValue() {
    try {
        CollectionUtils.sortAndDedup(bytesList);
        final int size = bytesList.size();
        final byte[] bytes = new byte[totalSize + (size + 1) * 5];
        final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
        out.writeVInt(size); // write total number of values
        for (int i = 0; i < size; i++) {
            final byte[] value = bytesList.get(i);
            final int valueLength = value.length;
            out.writeVInt(valueLength);
            out.writeBytes(value, 0, valueLength);
        }
        return new BytesRef(bytes, 0, out.getPosition());
    } catch (final IOException e) {
        throw new ElasticsearchException("Failed to get MinHash value",
                e);
    }

}
 
开发者ID:codelibs,项目名称:elasticsearch-minhash,代码行数:22,代码来源:MinHashFieldMapper.java

示例5: beforeClass

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws IOException {
  Random random = random();
  INTS = new int[COUNT];
  LONGS = new long[COUNT];
  RANDOM_TEST_BYTES = new byte[COUNT * (5 + 4 + 9 + 8)];
  final ByteArrayDataOutput bdo = new ByteArrayDataOutput(RANDOM_TEST_BYTES);
  for (int i = 0; i < COUNT; i++) {
    final int i1 = INTS[i] = random.nextInt();
    bdo.writeVInt(i1);
    bdo.writeInt(i1);

    final long l1;
    if (rarely()) {
      // a long with lots of zeroes at the end
      l1 = LONGS[i] = _TestUtil.nextLong(random, 0, Integer.MAX_VALUE) << 32;
    } else {
      l1 = LONGS[i] = _TestUtil.nextLong(random, 0, Long.MAX_VALUE);
    }
    bdo.writeVLong(l1);
    bdo.writeLong(l1);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:24,代码来源:TestIndexInput.java

示例6: testVariableBinary

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
public void testVariableBinary() throws Exception {
  BaseDirectoryWrapper dir = newFSDirectory(createTempDir("2BVariableBinary"));
  if (dir instanceof MockDirectoryWrapper) {
    ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
  }
  
  IndexWriter w = new IndexWriter(dir,
      new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
      .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH)
      .setRAMBufferSizeMB(256.0)
      .setMergeScheduler(new ConcurrentMergeScheduler())
      .setMergePolicy(newLogMergePolicy(false, 10))
      .setOpenMode(IndexWriterConfig.OpenMode.CREATE));

  Document doc = new Document();
  byte bytes[] = new byte[4];
  ByteArrayDataOutput encoder = new ByteArrayDataOutput(bytes);
  BytesRef data = new BytesRef(bytes);
  BinaryDocValuesField dvField = new BinaryDocValuesField("dv", data);
  doc.add(dvField);
  
  for (int i = 0; i < Integer.MAX_VALUE; i++) {
    encoder.reset(bytes);
    encoder.writeVInt(i % 65535); // 1, 2, or 3 bytes
    data.length = encoder.getPosition();
    w.addDocument(doc);
    if (i % 100000 == 0) {
      System.out.println("indexed: " + i);
      System.out.flush();
    }
  }
  
  w.forceMerge(1);
  w.close();
  
  System.out.println("verifying...");
  System.out.flush();
  
  DirectoryReader r = DirectoryReader.open(dir);
  int expectedValue = 0;
  ByteArrayDataInput input = new ByteArrayDataInput();
  for (AtomicReaderContext context : r.leaves()) {
    AtomicReader reader = context.reader();
    BinaryDocValues dv = reader.getBinaryDocValues("dv");
    for (int i = 0; i < reader.maxDoc(); i++) {
      final BytesRef term = dv.get(i);
      input.reset(term.bytes, term.offset, term.length);
      assertEquals(expectedValue % 65535, input.readVInt());
      assertTrue(input.eof());
      expectedValue++;
    }
  }
  
  r.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:57,代码来源:Test2BBinaryDocValues.java

示例7: testVariableBinary

import org.apache.lucene.store.ByteArrayDataOutput; //导入方法依赖的package包/类
public void testVariableBinary() throws Exception {
  BaseDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BVariableBinary"));
  if (dir instanceof MockDirectoryWrapper) {
    ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
  }
  
  IndexWriter w = new IndexWriter(dir,
      new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
      .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH)
      .setRAMBufferSizeMB(256.0)
      .setMergeScheduler(new ConcurrentMergeScheduler())
      .setMergePolicy(newLogMergePolicy(false, 10))
      .setOpenMode(IndexWriterConfig.OpenMode.CREATE));

  Document doc = new Document();
  byte bytes[] = new byte[4];
  ByteArrayDataOutput encoder = new ByteArrayDataOutput(bytes);
  BytesRef data = new BytesRef(bytes);
  BinaryDocValuesField dvField = new BinaryDocValuesField("dv", data);
  doc.add(dvField);
  
  for (int i = 0; i < Integer.MAX_VALUE; i++) {
    encoder.reset(bytes);
    encoder.writeVInt(i % 65535); // 1, 2, or 3 bytes
    data.length = encoder.getPosition();
    w.addDocument(doc);
    if (i % 100000 == 0) {
      System.out.println("indexed: " + i);
      System.out.flush();
    }
  }
  
  w.forceMerge(1);
  w.close();
  
  System.out.println("verifying...");
  System.out.flush();
  
  DirectoryReader r = DirectoryReader.open(dir);
  int expectedValue = 0;
  ByteArrayDataInput input = new ByteArrayDataInput();
  for (AtomicReaderContext context : r.leaves()) {
    AtomicReader reader = context.reader();
    BytesRef scratch = new BytesRef(bytes);
    BinaryDocValues dv = reader.getBinaryDocValues("dv");
    for (int i = 0; i < reader.maxDoc(); i++) {
      dv.get(i, scratch);
      input.reset(scratch.bytes, scratch.offset, scratch.length);
      assertEquals(expectedValue % 65535, input.readVInt());
      assertTrue(input.eof());
      expectedValue++;
    }
  }
  
  r.close();
  dir.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:58,代码来源:Test2BBinaryDocValues.java


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