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


Java RAMDirectory.openInput方法代码示例

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


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

示例1: testMarkRest

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
public void testMarkRest() throws Exception {
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("test", IOContext.DEFAULT);
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 1);
    }
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 2);
    }

    output.close();

    IndexInput input = dir.openInput("test", IOContext.DEFAULT);
    InputStreamIndexInput is = new InputStreamIndexInput(input, 4);
    assertThat(is.markSupported(), equalTo(true));
    assertThat(is.read(), equalTo(1));
    assertThat(is.read(), equalTo(1));
    is.mark(0);
    assertThat(is.read(), equalTo(1));
    assertThat(is.read(), equalTo(2));
    is.reset();
    assertThat(is.read(), equalTo(1));
    assertThat(is.read(), equalTo(2));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:InputStreamIndexInputTests.java

示例2: testReadWrite

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
@Test
public void testReadWrite() {
  Vector v1 = new ComplexVector(new short[] { -1, 8000, 16000 });
  RAMDirectory directory = new RAMDirectory();
  try {
    IndexOutput indexOutput = directory.createOutput("complexvectors.bin", IOContext.DEFAULT);
    v1.writeToLuceneStream(indexOutput);
    indexOutput.close();

    IndexInput indexInput = directory.openInput("complexvectors.bin", IOContext.DEFAULT);
    ComplexVector cv2 = new ComplexVector(3, Mode.POLAR_SPARSE);
    cv2.readFromLuceneStream(indexInput);
    assertFloatArrayEquals(
        new float[] {0, 0, -0.997290f, 0.073564f, 0.989176f, -0.1467304f},
        cv2.getCoordinates(), TOL);
  } catch (IOException e) {
    e.printStackTrace();
    fail();
  }
  directory.close();
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:22,代码来源:ComplexVectorTest.java

示例3: testGenerateRandomVectorWriteAndRead

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
@Test
public void testGenerateRandomVectorWriteAndRead() {
  Random random = new Random(0);

  Vector vector = VectorFactory.generateRandomVector(VectorType.BINARY, 64, 2, random);
  assertEquals("1100001111010001111111011010000000111011100001100010010010001111", vector.writeToString());

  RAMDirectory directory = new RAMDirectory();
  try {
    IndexOutput indexOutput = directory.createOutput("binaryvectors.bin", IOContext.DEFAULT);
    vector.writeToLuceneStream(indexOutput);
    indexOutput.close();
    IndexInput indexInput = directory.openInput("binaryvectors.bin", IOContext.DEFAULT);
    Vector vector2 = VectorFactory.createZeroVector(VectorType.BINARY, 64);
    assertEquals("0000000000000000000000000000000000000000000000000000000000000000", vector2.writeToString());
    vector2.readFromLuceneStream(indexInput);
    assertEquals("1100001111010001111111011010000000111011100001100010010010001111", vector2.writeToString());
  } catch (IOException e) {
    e.printStackTrace();
    fail();
  }
  directory.close();
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:24,代码来源:BinaryVectorTest.java

示例4: zip

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
private byte[] zip(RAMDirectory dir) throws IOException {
  ByteArrayOutputStream buf = new ByteArrayOutputStream();
  try (ZipOutputStream zip = new ZipOutputStream(buf)) {
    for (String name : dir.listAll()) {
      try (IndexInput in = dir.openInput(name, null)) {
        int len = (int) in.length();
        byte[] tmp = new byte[len];
        ZipEntry entry = new ZipEntry(name);
        entry.setSize(len);
        in.readBytes(tmp, 0, len);
        zip.putNextEntry(entry);
        zip.write(tmp, 0, len);
        zip.closeEntry();
      }
    }
  }

  return buf.toByteArray();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:DocIndexer.java

示例5: testSingleReadTwoBytesLimit

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
public void testSingleReadTwoBytesLimit() throws IOException {
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("test", IOContext.DEFAULT);
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 1);
    }
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 2);
    }

    output.close();

    IndexInput input = dir.openInput("test", IOContext.DEFAULT);

    assertThat(input.getFilePointer(), lessThan(input.length()));
    InputStreamIndexInput is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(), equalTo(1));
    assertThat(is.read(), equalTo(1));
    assertThat(is.read(), equalTo(-1));

    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(), equalTo(1));
    assertThat(is.read(), equalTo(2));
    assertThat(is.read(), equalTo(-1));

    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(), equalTo(2));
    assertThat(is.read(), equalTo(2));
    assertThat(is.read(), equalTo(-1));

    assertThat(input.getFilePointer(), equalTo(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(0L));
    assertThat(is.read(), equalTo(-1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:InputStreamIndexInputTests.java

示例6: testReadMultiFourBytesLimit

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
public void testReadMultiFourBytesLimit() throws IOException {
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("test", IOContext.DEFAULT);
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 1);
    }
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 2);
    }

    output.close();

    IndexInput input = dir.openInput("test", IOContext.DEFAULT);

    byte[] read = new byte[4];

    assertThat(input.getFilePointer(), lessThan(input.length()));
    InputStreamIndexInput is = new InputStreamIndexInput(input, 4);
    assertThat(is.actualSizeToRead(), equalTo(4L));
    assertThat(is.read(read), equalTo(4));
    assertThat(read[0], equalTo((byte) 1));
    assertThat(read[1], equalTo((byte) 1));
    assertThat(read[2], equalTo((byte) 1));
    assertThat(read[3], equalTo((byte) 2));

    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 4);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 2));
    assertThat(read[1], equalTo((byte) 2));

    assertThat(input.getFilePointer(), equalTo(input.length()));
    is = new InputStreamIndexInput(input, 4);
    assertThat(is.actualSizeToRead(), equalTo(0L));
    assertThat(is.read(read), equalTo(-1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:InputStreamIndexInputTests.java

示例7: testSave

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
public void testSave() throws IOException {
  final int valueCount = TestUtil.nextInt(random(), 1, 2048);
  for (int bpv = 1; bpv <= 64; ++bpv) {
    final int maxValue = (int) Math.min(PackedInts.maxValue(31), PackedInts.maxValue(bpv));
    final RAMDirectory directory = new RAMDirectory();
    List<PackedInts.Mutable> packedInts = createPackedInts(valueCount, bpv);
    for (PackedInts.Mutable mutable : packedInts) {
      for (int i = 0; i < mutable.size(); ++i) {
        mutable.set(i, random().nextInt(maxValue));
      }

      IndexOutput out = directory.createOutput("packed-ints.bin", IOContext.DEFAULT);
      mutable.save(out);
      out.close();

      IndexInput in = directory.openInput("packed-ints.bin", IOContext.DEFAULT);
      PackedInts.Reader reader = PackedInts.getReader(in);
      assertEquals(valueCount, reader.size());
      if (mutable instanceof Packed64SingleBlock) {
        // make sure that we used the right format so that the reader has
        // the same performance characteristics as the mutable that has been
        // serialized
        assertTrue(reader instanceof Packed64SingleBlock);
      } else {
        assertFalse(reader instanceof Packed64SingleBlock);
      }
      for (int i = 0; i < valueCount; ++i) {
        assertEquals(mutable.get(i), reader.get(i));
      }
      in.close();
      directory.deleteFile("packed-ints.bin");
    }
    directory.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:36,代码来源:TestPackedInts.java

示例8: testReadMultiTwoBytesLimit1

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
public void testReadMultiTwoBytesLimit1() throws IOException {
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("test", IOContext.DEFAULT);
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 1);
    }
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 2);
    }

    output.close();

    IndexInput input = dir.openInput("test", IOContext.DEFAULT);

    byte[] read = new byte[2];

    assertThat(input.getFilePointer(), lessThan(input.length()));
    InputStreamIndexInput is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 1));
    assertThat(read[1], equalTo((byte) 1));

    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 1));
    assertThat(read[1], equalTo((byte) 2));

    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 2));
    assertThat(read[1], equalTo((byte) 2));

    assertThat(input.getFilePointer(), equalTo(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(0L));
    assertThat(is.read(read), equalTo(-1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:43,代码来源:InputStreamIndexInputTests.java


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