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


Java ByteArrayDataOutput类代码示例

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


ByteArrayDataOutput类属于org.apache.lucene.store包,在下文中一共展示了ByteArrayDataOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testCloseIntoReader

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
public void testCloseIntoReader() throws IOException {
    try (TranslogWriter writer = translog.createWriter(0)) {
        final int numOps = randomIntBetween(8, 128);
        final byte[] bytes = new byte[4];
        final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
        for (int i = 0; i < numOps; i++) {
            out.reset(bytes);
            out.writeInt(i);
            writer.add(new BytesArray(bytes), randomNonNegativeLong());
        }
        writer.sync();
        final Checkpoint writerCheckpoint = writer.getCheckpoint();
        try (TranslogReader reader = writer.closeIntoReader()) {
            for (int i = 0; i < numOps; i++) {
                final ByteBuffer buffer = ByteBuffer.allocate(4);
                reader.readBytes(buffer, reader.getFirstOperationOffset() + 4 * i);
                buffer.flip();
                final int value = buffer.getInt();
                assertEquals(i, value);
            }
            final Checkpoint readerCheckpoint = reader.getCheckpoint();
            assertThat(readerCheckpoint, equalTo(writerCheckpoint));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TranslogTests.java

示例3: binaryValue

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
@Override
public BytesRef binaryValue() {
    CollectionUtils.sortAndDedup(values);

    // here is the trick:
    //  - the first value is zig-zag encoded so that eg. -5 would become positive and would be better compressed by vLong
    //  - for other values, we only encode deltas using vLong
    final byte[] bytes = new byte[values.size() * ByteUtils.MAX_BYTES_VLONG];
    final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
    ByteUtils.writeVLong(out, ByteUtils.zigZagEncode(values.get(0)));
    for (int i = 1; i < values.size(); ++i) {
        final long delta = values.get(i) - values.get(i - 1);
        ByteUtils.writeVLong(out, delta);
    }
    return new BytesRef(bytes, 0, out.getPosition());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:NumberFieldMapper.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testVLong

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
public void testVLong() throws IOException {
    final long[] data = new long[scaledRandomIntBetween(1000, 10000)];
    for (int i = 0; i < data.length; ++i) {
        switch (randomInt(4)) {
        case 0:
            data[i] = 0;
            break;
        case 1:
            data[i] = Long.MAX_VALUE;
            break;
        case 2:
            data[i] = Long.MIN_VALUE;
            break;
        case 3:
            data[i] = randomInt(1 << randomIntBetween(2,30));
            break;
        case 4:
            data[i] = randomLong();
            break;
        default:
            throw new AssertionError();
        }
    }
    final byte[] encoded = new byte[ByteUtils.MAX_BYTES_VLONG * data.length];
    ByteArrayDataOutput out = new ByteArrayDataOutput(encoded);
    for (int i = 0; i < data.length; ++i) {
        final int pos = out.getPosition();
        ByteUtils.writeVLong(out, data[i]);
        if (data[i] < 0) {
            assertEquals(ByteUtils.MAX_BYTES_VLONG, out.getPosition() - pos);
        }
    }
    final ByteArrayDataInput in = new ByteArrayDataInput(encoded);
    for (int i = 0; i < data.length; ++i) {
        assertEquals(data[i], ByteUtils.readVLong(in));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:ByteUtilsTests.java

示例9: encode

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
@Override
protected void encode(ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer, BytesRef spare, BytesRef payload, Set<BytesRef> contexts, long weight) throws IOException {
  if (spare.length + 4 >= buffer.length) {
    buffer = ArrayUtil.grow(buffer, spare.length + 4);
  }
  output.reset(buffer);
  output.writeBytes(spare.bytes, spare.offset, spare.length);
  output.writeInt(encodeWeight(weight));
  writer.write(buffer, 0, output.getPosition());
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:WFSTCompletionLookup.java

示例10: sort

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
private ByteSequencesReader sort() throws IOException {
  String prefix = getClass().getSimpleName();
  File directory = OfflineSorter.defaultTempDir();
  tempInput = File.createTempFile(prefix, ".input", directory);
  tempSorted = File.createTempFile(prefix, ".sorted", directory);
  
  final ByteSequencesWriter writer = new ByteSequencesWriter(tempInput);
  boolean success = false;
  try {
    BytesRef spare;
    byte[] buffer = new byte[0];
    ByteArrayDataOutput output = new ByteArrayDataOutput(buffer);

    while ((spare = source.next()) != null) {
      encode(writer, output, buffer, spare, source.weight());
    }
    writer.close();
    new OfflineSorter(tieBreakByCostComparator).sort(tempInput, tempSorted);
    ByteSequencesReader reader = new ByteSequencesReader(tempSorted);
    success = true;
    return reader;
    
  } finally {
    if (success) {
      IOUtils.close(writer);
    } else {
      try {
        IOUtils.closeWhileHandlingException(writer);
      } finally {
        close();
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:SortedTermFreqIteratorWrapper.java

示例11: encode

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
/** encodes an entry (bytes+weight) to the provided writer */
protected void encode(ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer, BytesRef spare, long weight) throws IOException {
  if (spare.length + 8 >= buffer.length) {
    buffer = ArrayUtil.grow(buffer, spare.length + 8);
  }
  output.reset(buffer);
  output.writeBytes(spare.bytes, spare.offset, spare.length);
  output.writeLong(weight);
  writer.write(buffer, 0, output.getPosition());
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:SortedTermFreqIteratorWrapper.java

示例12: sort

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
private ByteSequencesReader sort() throws IOException {
  String prefix = getClass().getSimpleName();
  File directory = OfflineSorter.defaultTempDir();
  tempInput = File.createTempFile(prefix, ".input", directory);
  tempSorted = File.createTempFile(prefix, ".sorted", directory);
  
  final OfflineSorter.ByteSequencesWriter writer = new OfflineSorter.ByteSequencesWriter(tempInput);
  boolean success = false;
  try {
    BytesRef spare;
    byte[] buffer = new byte[0];
    ByteArrayDataOutput output = new ByteArrayDataOutput(buffer);

    while ((spare = source.next()) != null) {
      encode(writer, output, buffer, spare, source.payload(), source.contexts(), source.weight());
    }
    writer.close();
    new OfflineSorter(tieBreakByCostComparator).sort(tempInput, tempSorted);
    ByteSequencesReader reader = new OfflineSorter.ByteSequencesReader(tempSorted);
    success = true;
    return reader;
    
  } finally {
    if (success) {
      IOUtils.close(writer);
    } else {
      try {
        IOUtils.closeWhileHandlingException(writer);
      } finally {
        close();
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:SortedInputIterator.java

示例13: compress

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
static byte[] compress(Compressor compressor, byte[] decompressed, int off, int len) throws IOException {
  byte[] compressed = new byte[len * 2 + 16]; // should be enough
  ByteArrayDataOutput out = new ByteArrayDataOutput(compressed);
  compressor.compress(decompressed, off, len, out);
  final int compressedLen = out.getPosition();
  return Arrays.copyOf(compressed, compressedLen);
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:AbstractTestCompressionMode.java

示例14: encode

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
@Override
protected void encode(ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer, BytesRef spare, long weight) throws IOException {
  if (spare.length + 4 >= buffer.length) {
    buffer = ArrayUtil.grow(buffer, spare.length + 4);
  }
  output.reset(buffer);
  output.writeBytes(spare.bytes, spare.offset, spare.length);
  output.writeInt(encodeWeight(weight));
  writer.write(buffer, 0, output.getPosition());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:11,代码来源:WFSTCompletionLookup.java

示例15: sort

import org.apache.lucene.store.ByteArrayDataOutput; //导入依赖的package包/类
private Sort.ByteSequencesReader sort() throws IOException {
  String prefix = getClass().getSimpleName();
  File directory = Sort.defaultTempDir();
  tempInput = File.createTempFile(prefix, ".input", directory);
  tempSorted = File.createTempFile(prefix, ".sorted", directory);
  
  final Sort.ByteSequencesWriter writer = new Sort.ByteSequencesWriter(tempInput);
  boolean success = false;
  try {
    BytesRef spare;
    byte[] buffer = new byte[0];
    ByteArrayDataOutput output = new ByteArrayDataOutput(buffer);

    while ((spare = source.next()) != null) {
      encode(writer, output, buffer, spare, source.weight());
    }
    writer.close();
    new Sort(tieBreakByCostComparator).sort(tempInput, tempSorted);
    ByteSequencesReader reader = new Sort.ByteSequencesReader(tempSorted);
    success = true;
    return reader;
    
  } finally {
    if (success) {
      IOUtils.close(writer);
    } else {
      try {
        IOUtils.closeWhileHandlingException(writer);
      } finally {
        close();
      }
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:35,代码来源:SortedTermFreqIteratorWrapper.java


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