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


Java IndexOutput类代码示例

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


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

示例1: createVerifyingOutput

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
/**
 * The returned IndexOutput validates the files checksum.
 * <p>
 * Note: Checksums are calculated by default since version 4.8.0. This method only adds the
 * verification against the checksum in the given metadata and does not add any significant overhead.
 */
public IndexOutput createVerifyingOutput(String fileName, final StoreFileMetaData metadata, final IOContext context) throws IOException {
    IndexOutput output = directory().createOutput(fileName, context);
    boolean success = false;
    try {
        assert metadata.writtenBy() != null;
        assert metadata.writtenBy().onOrAfter(StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION);
        output = new LuceneVerifyingIndexOutput(metadata, output);
        success = true;
    } finally {
        if (success == false) {
            IOUtils.closeWhileHandlingException(output);
        }
    }
    return output;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:Store.java

示例2: markStoreCorrupted

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
/**
 * Marks this store as corrupted. This method writes a <tt>corrupted_${uuid}</tt> file containing the given exception
 * message. If a store contains a <tt>corrupted_${uuid}</tt> file {@link #isMarkedCorrupted()} will return <code>true</code>.
 */
public void markStoreCorrupted(IOException exception) throws IOException {
    ensureOpen();
    if (!isMarkedCorrupted()) {
        String uuid = CORRUPTED + UUIDs.randomBase64UUID();
        try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) {
            CodecUtil.writeHeader(output, CODEC, VERSION);
            BytesStreamOutput out = new BytesStreamOutput();
            out.writeException(exception);
            BytesReference bytes = out.bytes();
            output.writeVInt(bytes.length());
            BytesRef ref = bytes.toBytesRef();
            output.writeBytes(ref.bytes, ref.offset, ref.length);
            CodecUtil.writeFooter(output);
        } catch (IOException ex) {
            logger.warn("Can't mark store as corrupted", ex);
        }
        directory().sync(Collections.singleton(uuid));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:Store.java

示例3: testStatsDirWrapper

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
public void testStatsDirWrapper() throws IOException {
    Directory dir = newDirectory();
    Directory target = newDirectory();
    RecoveryState.Index indexStats = new RecoveryState.Index();
    StoreRecovery.StatsDirectoryWrapper wrapper = new StoreRecovery.StatsDirectoryWrapper(target, indexStats);
    try (IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT)) {
        CodecUtil.writeHeader(output, "foo", 0);
        int numBytes = randomIntBetween(100, 20000);
        for (int i = 0; i < numBytes; i++) {
            output.writeByte((byte)i);
        }
        CodecUtil.writeFooter(output);
    }
    wrapper.copyFrom(dir, "foo.bar", "bar.foo", IOContext.DEFAULT);
    assertNotNull(indexStats.getFileDetails("bar.foo"));
    assertNull(indexStats.getFileDetails("foo.bar"));
    assertEquals(dir.fileLength("foo.bar"), indexStats.getFileDetails("bar.foo").length());
    assertEquals(dir.fileLength("foo.bar"), indexStats.getFileDetails("bar.foo").recovered());
    assertFalse(indexStats.getFileDetails("bar.foo").reused());
    IOUtils.close(dir, target);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:StoreRecoveryTests.java

示例4: appendRandomData

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
private void appendRandomData(IndexOutput output) throws IOException {
    int numBytes = randomIntBetween(1, 1024);
    final BytesRef ref = new BytesRef(scaledRandomIntBetween(1, numBytes));
    ref.length = ref.bytes.length;
    while (numBytes > 0) {
        if (random().nextInt(10) == 0) {
            output.writeByte(randomByte());
            numBytes--;
        } else {
            for (int i = 0; i<ref.length; i++) {
                ref.bytes[i] = randomByte();
            }
            final int min = Math.min(numBytes, ref.bytes.length);
            output.writeBytes(ref.bytes, ref.offset, min);
            numBytes -= min;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:StoreTests.java

示例5: testCheckIntegrity

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

    try (IndexOutput output = dir.createOutput("lucene_checksum.bin", 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);
            luceneFileLength += bytesRef.length;
        }
        CodecUtil.writeFooter(output);
        luceneFileLength += CodecUtil.footerLength();

    }

    final long luceneChecksum;
    try (IndexInput indexInput = dir.openInput("lucene_checksum.bin", IOContext.DEFAULT)) {
        assertEquals(luceneFileLength, indexInput.length());
        luceneChecksum = CodecUtil.retrieveChecksum(indexInput);
    }

    dir.close();

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

示例6: corruptFile

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
private void corruptFile(Directory dir, String fileIn, String fileOut) throws IOException {
    IndexInput input = dir.openInput(fileIn, IOContext.READONCE);
    IndexOutput output = dir.createOutput(fileOut, IOContext.DEFAULT);
    long len = input.length();
    byte[] b = new byte[1024];
    long broken = randomInt((int) len-1);
    long pos = 0;
    while (pos < len) {
        int min = (int) Math.min(input.length() - pos, b.length);
        input.readBytes(b, 0, min);
        if (broken >= pos && broken < pos + min) {
            // Flip one byte
            int flipPos = (int) (broken - pos);
            b[flipPos] = (byte) (b[flipPos] ^ 42);
        }
        output.writeBytes(b, min);
        pos += min;
    }
    IOUtils.close(input, output);

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

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

示例8: writeClearedDgaps

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
/** Write as a d-gaps list */
private void writeClearedDgaps(IndexOutput output) throws IOException {
  output.writeInt(-1);            // mark using d-gaps                         
  output.writeInt(size());        // write size
  output.writeInt(count());       // write count
  int last=0;
  int numCleared = size()-count();
  for (int i=0; i<bits.length && numCleared>0; i++) {
    if (bits[i] != (byte) 0xff) {
      output.writeVInt(i-last);
      output.writeByte(bits[i]);
      last = i;
      numCleared -= (8-BitUtil.bitCount(bits[i]));
      assert numCleared >= 0 || (i == (bits.length-1) && numCleared == -(8-(size&7)));
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:BitVector.java

示例9: writeBlock

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
/**
 * Write a block of data (<code>For</code> format).
 *
 * @param data     the data to write
 * @param encoded  a buffer to use to encode data
 * @param out      the destination output
 * @throws IOException If there is a low-level I/O error
 */
void writeBlock(int[] data, byte[] encoded, IndexOutput out) throws IOException {
  if (isAllEqual(data)) {
    out.writeByte((byte) ALL_VALUES_EQUAL);
    out.writeVInt(data[0]);
    return;
  }

  final int numBits = bitsRequired(data);
  assert numBits > 0 && numBits <= 32 : numBits;
  final PackedInts.Encoder encoder = encoders[numBits];
  final int iters = iterations[numBits];
  assert iters * encoder.byteValueCount() >= BLOCK_SIZE;
  final int encodedSize = encodedSizes[numBits];
  assert iters * encoder.byteBlockCount() >= encodedSize;

  out.writeByte((byte) numBits);

  encoder.encode(data, 0, encoded, 0, iters);
  out.writeBytes(encoded, encodedSize);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:ForUtil.java

示例10: Lucene41SkipWriter

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
public Lucene41SkipWriter(int maxSkipLevels, int blockSize, int docCount, IndexOutput docOut, IndexOutput posOut, IndexOutput payOut) {
  super(blockSize, 8, maxSkipLevels, docCount);
  this.docOut = docOut;
  this.posOut = posOut;
  this.payOut = payOut;
  
  lastSkipDoc = new int[maxSkipLevels];
  lastSkipDocPointer = new long[maxSkipLevels];
  if (posOut != null) {
    lastSkipPosPointer = new long[maxSkipLevels];
    if (payOut != null) {
      lastSkipPayPointer = new long[maxSkipLevels];
    }
    lastPayloadByteUpto = new int[maxSkipLevels];
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:Lucene41SkipWriter.java

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

示例12: cleanOpenFiles

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
protected void cleanOpenFiles() {
    // clean open index outputs
    Iterator<Entry<String, IndexOutput>> iterator = openIndexOutputs.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, IndexOutput> entry = iterator.next();
        logger.trace("closing IndexOutput file [{}]", entry.getValue());
        try {
            entry.getValue().close();
        } catch (Throwable t) {
            logger.debug("error while closing recovery output [{}]", t, entry.getValue());
        }
        iterator.remove();
    }
    // trash temporary files
    for (String file : tempFileNames.keySet()) {
        logger.trace("cleaning temporary file [{}]", file);
        store.deleteQuiet(file);
    }
    legacyChecksums.clear();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:RecoveryStatus.java

示例13: CompletionFieldsConsumer

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
public CompletionFieldsConsumer(SegmentWriteState state) throws IOException {
    this.delegatesFieldsConsumer = delegatePostingsFormat.fieldsConsumer(state);
    String suggestFSTFile = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
    IndexOutput output = null;
    boolean success = false;
    try {
        output = state.directory.createOutput(suggestFSTFile, state.context);
        CodecUtil.writeHeader(output, CODEC_NAME, SUGGEST_VERSION_CURRENT);
        /*
         * we write the delegate postings format name so we can load it
         * without getting an instance in the ctor
         */
        output.writeString(delegatePostingsFormat.getName());
        output.writeString(writeProvider.getName());
        this.suggestFieldsConsumer = writeProvider.consumer(output);
        success = true;
    } finally {
        if (!success) {
            IOUtils.closeWhileHandlingException(output);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:Completion090PostingsFormat.java

示例14: testRawIndexInputRead

import org.apache.lucene.store.IndexOutput; //导入依赖的package包/类
public void testRawIndexInputRead() throws IOException {
  for (int i = 0; i < 10; i++) {
    Random random = random();
    final Directory dir = newDirectory();
    IndexOutput os = dir.createOutput("foo", newIOContext(random));
    os.writeBytes(READ_TEST_BYTES, READ_TEST_BYTES.length);
    os.close();
    IndexInput is = dir.openInput("foo", newIOContext(random));
    checkReads(is, IOException.class);
    is.close();
  
    os = dir.createOutput("bar", newIOContext(random));
    os.writeBytes(RANDOM_TEST_BYTES, RANDOM_TEST_BYTES.length);
    os.close();
    is = dir.openInput("bar", newIOContext(random));
    checkRandomReads(is);
    is.close();
    dir.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestIndexInput.java

示例15: 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:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:22,代码来源:TestMixedDirectory.java


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