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


Java IndexOutput.close方法代码示例

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


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

示例1: testMarkRest

import org.apache.lucene.store.IndexOutput; //导入方法依赖的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: writeSegmentsGen

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/**
 * A utility for writing the {@link IndexFileNames#SEGMENTS_GEN} file to a
 * {@link Directory}.
 * 
 * <p>
 * <b>NOTE:</b> this is an internal utility which is kept public so that it's
 * accessible by code from other packages. You should avoid calling this
 * method unless you're absolutely sure what you're doing!
 * 
 * @lucene.internal
 */
public static void writeSegmentsGen(Directory dir, long generation) {
  try {
    IndexOutput genOutput = dir.createOutput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
    try {
      genOutput.writeInt(FORMAT_SEGMENTS_GEN_CURRENT);
      genOutput.writeLong(generation);
      genOutput.writeLong(generation);
      CodecUtil.writeFooter(genOutput);
    } finally {
      genOutput.close();
      dir.sync(Collections.singleton(IndexFileNames.SEGMENTS_GEN));
    }
  } catch (Throwable t) {
    // It's OK if we fail to write this file since it's
    // used only as one of the retry fallbacks.
    IOUtils.deleteFilesIgnoringExceptions(dir, IndexFileNames.SEGMENTS_GEN);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:SegmentInfos.java

示例3: testMixedDirectoryAndPolicy

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public void testMixedDirectoryAndPolicy() throws IOException {
  Directory readDir = new RAMDirectory();
  updateIndex(readDir, 0, numDocsPerUpdate,
      new KeepOnlyLastCommitDeletionPolicy());

  verify(readDir, numDocsPerUpdate);

  IndexOutput out =
      readDir.createOutput("_" + (numDocsPerUpdate / maxBufferedDocs + 2)
          + ".cfs");
  out.writeInt(0);
  out.close();

  Directory writeDir = new RAMDirectory();
  Directory mixedDir = new MixedDirectory(readDir, writeDir);
  updateIndex(mixedDir, numDocsPerUpdate, numDocsPerUpdate,
      new MixedDeletionPolicy());

  verify(readDir, numDocsPerUpdate);
  verify(mixedDir, 2 * numDocsPerUpdate);
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:22,代码来源:TestMixedDirectory.java

示例4: testReadWrite

import org.apache.lucene.store.IndexOutput; //导入方法依赖的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

示例5: testNotEnoughValues

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** test exception is delivered if you add the wrong number of values */
public void testNotEnoughValues() throws Exception {
  Directory dir = newDirectory();
  int bitsPerValue = DirectWriter.bitsRequired(2);
  IndexOutput output = dir.createOutput("foo", IOContext.DEFAULT);
  DirectWriter writer = DirectWriter.getInstance(output, 5, bitsPerValue);
  writer.add(1);
  writer.add(0);
  writer.add(2);
  writer.add(1);
  try {
    writer.finish();
    fail("didn't get expected exception");
  } catch (IllegalStateException expected) {
    assertTrue(expected.getMessage().startsWith("Wrong number of values added"));
  }
  output.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestDirectPacked.java

示例6: testSimple

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** simple encode/decode */
public void testSimple() throws Exception {
  Directory dir = newDirectory();
  int bitsPerValue = DirectWriter.bitsRequired(2);
  IndexOutput output = dir.createOutput("foo", IOContext.DEFAULT);
  DirectWriter writer = DirectWriter.getInstance(output, 5, bitsPerValue);
  writer.add(1);
  writer.add(0);
  writer.add(2);
  writer.add(1);
  writer.add(2);
  writer.finish();
  output.close();
  IndexInput input = dir.openInput("foo", IOContext.DEFAULT);
  NumericDocValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsPerValue);
  assertEquals(1, reader.get(0));
  assertEquals(0, reader.get(1));
  assertEquals(2, reader.get(2));
  assertEquals(1, reader.get(3));
  assertEquals(2, reader.get(4));
  input.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestDirectPacked.java

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

示例8: testVerifyingIndexInput

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public void testVerifyingIndexInput() throws IOException {
    Directory dir = newDirectory();
    IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT);
    int iters = scaledRandomIntBetween(10, 100);
    for (int i = 0; i < iters; i++) {
        BytesRef bytesRef = new BytesRef(TestUtil.randomRealisticUnicodeString(random(), 10, 1024));
        output.writeBytes(bytesRef.bytes, bytesRef.offset, bytesRef.length);
    }
    CodecUtil.writeFooter(output);
    output.close();

    // Check file
    IndexInput indexInput = dir.openInput("foo.bar", IOContext.DEFAULT);
    long checksum = CodecUtil.retrieveChecksum(indexInput);
    indexInput.seek(0);
    IndexInput verifyingIndexInput = new Store.VerifyingIndexInput(dir.openInput("foo.bar", IOContext.DEFAULT));
    readIndexInputFullyWithRandomSeeks(verifyingIndexInput);
    Store.verify(verifyingIndexInput);
    assertThat(checksum, equalTo(((ChecksumIndexInput) verifyingIndexInput).getChecksum()));
    IOUtils.close(indexInput, verifyingIndexInput);

    // Corrupt file and check again
    corruptFile(dir, "foo.bar", "foo1.bar");
    verifyingIndexInput = new Store.VerifyingIndexInput(dir.openInput("foo1.bar", IOContext.DEFAULT));
    readIndexInputFullyWithRandomSeeks(verifyingIndexInput);
    try {
        Store.verify(verifyingIndexInput);
        fail("should be a corrupted index");
    } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
        // ok
    }
    IOUtils.close(verifyingIndexInput);
    IOUtils.close(dir);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:StoreTests.java

示例9: testSingleReadTwoBytesLimit

import org.apache.lucene.store.IndexOutput; //导入方法依赖的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

示例10: testReadMultiFourBytesLimit

import org.apache.lucene.store.IndexOutput; //导入方法依赖的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

示例11: write

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Save a single segment's info. */
@Override
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
  final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene40SegmentInfoFormat.SI_EXTENSION);
  si.addFile(fileName);

  final IndexOutput output = dir.createOutput(fileName, ioContext);

  boolean success = false;
  try {
    CodecUtil.writeHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT);
    // Write the Lucene version that created this segment, since 3.1
    output.writeString(si.getVersion().toString());
    output.writeInt(si.getDocCount());

    output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
    output.writeStringStringMap(si.getDiagnostics());
    output.writeStringStringMap(Collections.<String,String>emptyMap());
    output.writeStringSet(si.files());

    success = true;
  } finally {
    if (!success) {
      IOUtils.closeWhileHandlingException(output);
      // TODO: why must we do this? do we not get tracking dir wrapper?
      IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
    } else {
      output.close();
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:Lucene40SegmentInfoWriter.java

示例12: write

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Save a single segment's info. */
@Override
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
  final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene46SegmentInfoFormat.SI_EXTENSION);
  si.addFile(fileName);

  final IndexOutput output = dir.createOutput(fileName, ioContext);

  boolean success = false;
  try {
    CodecUtil.writeHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT);
    Version version = si.getVersion();
    if (version.major < 3 || version.major > 4) {
      throw new IllegalArgumentException("invalid major version: should be 3 or 4 but got: " + version.major + " segment=" + si);
    }
    // Write the Lucene version that created this segment, since 3.1
    output.writeString(version.toString());
    output.writeInt(si.getDocCount());

    output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
    output.writeStringStringMap(si.getDiagnostics());
    output.writeStringSet(si.files());
    CodecUtil.writeFooter(output);
    success = true;
  } finally {
    if (!success) {
      IOUtils.closeWhileHandlingException(output);
      // TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?
      IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
    } else {
      output.close();
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:Lucene46SegmentInfoWriter.java

示例13: readRAMFiles

import org.apache.lucene.store.IndexOutput; //导入方法依赖的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

示例14: testManySubFiles

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public void testManySubFiles() throws IOException {

    final Directory d = newFSDirectory(createTempDir("CFSManySubFiles"));
    final int FILE_COUNT = atLeast(500);

    for(int fileIdx=0;fileIdx<FILE_COUNT;fileIdx++) {
      IndexOutput out = d.createOutput("file." + fileIdx, newIOContext(random()));
      out.writeByte((byte) fileIdx);
      out.close();
    }
    
    final CompoundFileDirectory cfd = new CompoundFileDirectory(d, "c.cfs", newIOContext(random()), true);
    for(int fileIdx=0;fileIdx<FILE_COUNT;fileIdx++) {
      final String fileName = "file." + fileIdx;
      d.copy(cfd, fileName, fileName, newIOContext(random()));
    }
    cfd.close();

    final IndexInput[] ins = new IndexInput[FILE_COUNT];
    final CompoundFileDirectory cfr = new CompoundFileDirectory(d, "c.cfs", newIOContext(random()), false);
    for(int fileIdx=0;fileIdx<FILE_COUNT;fileIdx++) {
      ins[fileIdx] = cfr.openInput("file." + fileIdx, newIOContext(random()));
    }

    for(int fileIdx=0;fileIdx<FILE_COUNT;fileIdx++) {
      assertEquals((byte) fileIdx, ins[fileIdx].readByte());
    }

    for(int fileIdx=0;fileIdx<FILE_COUNT;fileIdx++) {
      ins[fileIdx].close();
    }
    cfr.close();
    d.close();
  }
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:TestCompoundFile.java

示例15: testSegmentsChecksumError

import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public void testSegmentsChecksumError() throws IOException {
  Directory dir = newDirectory();

  IndexWriter writer = null;

  writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));

  // add 100 documents
  for (int i = 0; i < 100; i++) {
    addDoc(writer);
  }

  // close
  writer.close();

  long gen = SegmentInfos.getLastCommitGeneration(dir);
  assertTrue("segment generation should be > 0 but got " + gen, gen > 0);

  final String segmentsFileName = SegmentInfos.getLastCommitSegmentsFileName(dir);
  IndexInput in = dir.openInput(segmentsFileName, newIOContext(random()));
  IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1+gen), newIOContext(random()));
  out.copyBytes(in, in.length()-1);
  byte b = in.readByte();
  out.writeByte((byte) (1+b));
  out.close();
  in.close();

  IndexReader reader = null;
  try {
    reader = DirectoryReader.open(dir);
  } catch (IOException e) {
    e.printStackTrace(System.out);
    fail("segmentInfos failed to retry fallback to correct segments_N file");
  }
  reader.close();
  
  // should remove the corrumpted segments_N
  new IndexWriter(dir, newIndexWriterConfig(null)).close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:TestIndexWriterExceptions.java


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