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


Java RAMDirectory.createOutput方法代码示例

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


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

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

示例6: readRAMFiles

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
/**
 * Read a number of files from a data input to a ram directory.
 * @param in  the data input
 * @param dir  the ram directory
 * @throws IOException
 */
public static void readRAMFiles(DataInput in, RAMDirectory dir) throws IOException {
  int numFiles = in.readInt();

  for (int i = 0; i < numFiles; i++) {
    String name = Text.readString(in);
    long length = in.readLong();

    if (length > 0) {
      // can we avoid the extra copy?
      IndexOutput output = null;
      try {
        IOContext context = new IOContext();
        output = dir.createOutput(name, context);

        int position = 0;
        byte[] buffer = new byte[BUFFER_SIZE];

        while (position < length) {
          int len = position + BUFFER_SIZE <= length ? BUFFER_SIZE : (int) (length - position);
          in.readFully(buffer, 0, len);
          output.writeBytes(buffer, 0, len);
          position += len;
        }
      } finally {
        if (output != null) {
          output.close();
        }
      }
    }
  }
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:38,代码来源:RAMDirectoryUtil.java

示例7: readRAMFiles

import org.apache.lucene.store.RAMDirectory; //导入方法依赖的package包/类
/**
 * Read a number of files from a data input to a ram directory.
 * @param in  the data input
 * @param dir  the ram directory
 * @throws IOException
 */
public static void readRAMFiles(DataInput in, RAMDirectory dir)
    throws IOException {
  int numFiles = in.readInt();

  for (int i = 0; i < numFiles; i++) {
    String name = Text.readString(in);
    long length = in.readLong();

    if (length > 0) {
      // can we avoid the extra copy?
      IndexOutput output = null;
      try {
        output = dir.createOutput(name);

        int position = 0;
        byte[] buffer = new byte[BUFFER_SIZE];

        while (position < length) {
          int len =
              position + BUFFER_SIZE <= length ? BUFFER_SIZE
                  : (int) (length - position);
          in.readFully(buffer, 0, len);
          output.writeBytes(buffer, 0, len);
          position += len;
        }
      } finally {
        if (output != null) {
          output.close();
        }
      }
    }
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:40,代码来源:RAMDirectoryUtil.java

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

示例9: 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.createOutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。