當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexOutput.writeInt方法代碼示例

本文整理匯總了Java中org.apache.lucene.store.IndexOutput.writeInt方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexOutput.writeInt方法的具體用法?Java IndexOutput.writeInt怎麽用?Java IndexOutput.writeInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.store.IndexOutput的用法示例。


在下文中一共展示了IndexOutput.writeInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

示例3: writeDgaps

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
/** Write as a d-gaps list */
private void writeDgaps(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 n = count();
  int m = bits.length;
  for (int i=0; i<m && n>0; i++) {
    if (bits[i]!=0) {
      output.writeVInt(i-last);
      output.writeByte(bits[i]);
      last = i;
      n -= BYTE_COUNTS[bits[i] & 0xFF];
    }
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:18,代碼來源:BitVector_3_1_0.java

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

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

示例6: writeToLuceneStream

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
@Override
/**
 * Transforms vector to cartesian form and writes vector out in dense format.
 */
public void writeToLuceneStream(IndexOutput outputStream) {
  toCartesian();
  for (int i = 0; i < dimension * 2; ++i) {
    try {
      outputStream.writeInt(Float.floatToIntBits(coordinates[i]));
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:15,代碼來源:ComplexVector.java

示例7: init

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
@Override
public void init(IndexOutput termsOut) throws IOException {
  CodecUtil.writeHeader(termsOut, CODEC, VERSION_CURRENT);
  // TODO: -- just ask skipper to "start" here
  termsOut.writeInt(skipInterval);                // write skipInterval
  termsOut.writeInt(maxSkipLevels);               // write maxSkipLevels
  termsOut.writeInt(skipMinimum);                 // write skipMinimum
}
 
開發者ID:europeana,項目名稱:search,代碼行數:9,代碼來源:SepPostingsWriter.java

示例8: addShortsField

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
private void addShortsField(FieldInfo field, IndexOutput output, Iterable<Number> values) throws IOException {
  field.putAttribute(legacyKey, LegacyDocValuesType.FIXED_INTS_16.name());
  CodecUtil.writeHeader(output, 
                        Lucene40DocValuesFormat.INTS_CODEC_NAME, 
                        Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
  output.writeInt(2); // size
  for (Number n : values) {
    output.writeShort(n == null ? 0 : n.shortValue());
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:11,代碼來源:Lucene40DocValuesWriter.java

示例9: addIntsField

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
private void addIntsField(FieldInfo field, IndexOutput output, Iterable<Number> values) throws IOException {
  field.putAttribute(legacyKey, LegacyDocValuesType.FIXED_INTS_32.name());
  CodecUtil.writeHeader(output, 
                        Lucene40DocValuesFormat.INTS_CODEC_NAME, 
                        Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
  output.writeInt(4); // size
  for (Number n : values) {
    output.writeInt(n == null ? 0 : n.intValue());
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:11,代碼來源:Lucene40DocValuesWriter.java

示例10: addFixedStraightBytesField

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
private void addFixedStraightBytesField(FieldInfo field, IndexOutput output, Iterable<BytesRef> values, int length) throws IOException {
  field.putAttribute(legacyKey, LegacyDocValuesType.BYTES_FIXED_STRAIGHT.name());

  CodecUtil.writeHeader(output, 
                        Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_CODEC_NAME,
                        Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_VERSION_CURRENT);
  
  output.writeInt(length);
  for (BytesRef v : values) {
    if (v != null) {
      output.writeBytes(v.bytes, v.offset, v.length);
    }
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:15,代碼來源:Lucene40DocValuesWriter.java

示例11: init

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
@Override
public void init(IndexOutput termsOut) throws IOException {
  CodecUtil.writeHeader(termsOut, Lucene40PostingsReader.TERMS_CODEC, Lucene40PostingsReader.VERSION_CURRENT);
  termsOut.writeInt(skipInterval);                // write skipInterval
  termsOut.writeInt(maxSkipLevels);               // write maxSkipLevels
  termsOut.writeInt(skipMinimum);                 // write skipMinimum
}
 
開發者ID:europeana,項目名稱:search,代碼行數:8,代碼來源:Lucene40PostingsWriter.java

示例12: createOutput

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
@Override
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
  final IndexOutput out = dir.createOutput(fileName, context);
  boolean success = false;
  try {
    out.writeInt(baseBlockSize);
    VariableIntBlockIndexOutput ret = new VariableIntBlockIndexOutput(out, 2*baseBlockSize) {
      int pendingCount;
      final int[] buffer = new int[2+2*baseBlockSize];
      
      @Override
      protected int add(int value) throws IOException {
        buffer[pendingCount++] = value;
        // silly variable block length int encoder: if
        // first value <= 3, we write N vints at once;
        // else, 2*N
        final int flushAt = buffer[0] <= 3 ? baseBlockSize : 2*baseBlockSize;
        
        // intentionally be non-causal here:
        if (pendingCount == flushAt+1) {
          for(int i=0;i<flushAt;i++) {
            out.writeVInt(buffer[i]);
          }
          buffer[0] = buffer[flushAt];
          pendingCount = 1;
          return flushAt;
        } else {
          return 0;
        }
      }
    };
    success = true;
    return ret;
  } finally {
    if (!success) {
      IOUtils.closeWhileHandlingException(out);
    }
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:40,代碼來源:MockVariableIntBlockPostingsFormat.java

示例13: testWritingAndReadingAFile

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
@Test
public void testWritingAndReadingAFile() throws IOException {
  String[] listAll = directory.listAll();
  for (String file : listAll) {
    directory.deleteFile(file);
  }
  
  IndexOutput output = directory.createOutput("testing.test", new IOContext());
  output.writeInt(12345);
  output.flush();
  output.close();

  IndexInput input = directory.openInput("testing.test", new IOContext());
  assertEquals(12345, input.readInt());
  input.close();

  listAll = directory.listAll();
  assertEquals(1, listAll.length);
  assertEquals("testing.test", listAll[0]);

  assertEquals(4, directory.fileLength("testing.test"));

  IndexInput input1 = directory.openInput("testing.test", new IOContext());

  IndexInput input2 = (IndexInput) input1.clone();
  assertEquals(12345, input2.readInt());
  input2.close();

  assertEquals(12345, input1.readInt());
  input1.close();

  assertFalse(slowFileExists(directory, "testing.test.other"));
  assertTrue(slowFileExists(directory, "testing.test"));
  directory.deleteFile("testing.test");
  assertFalse(slowFileExists(directory, "testing.test"));
}
 
開發者ID:europeana,項目名稱:search,代碼行數:37,代碼來源:HdfsDirectoryTest.java

示例14: insertData

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
private void insertData() throws IOException {
    final byte[] test = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    final IndexOutput indexOutput = jdbcDirectory.createOutput("value1", new IOContext());
    indexOutput.writeInt(-1);
    indexOutput.writeLong(10);
    indexOutput.writeInt(0);
    indexOutput.writeInt(0);
    indexOutput.writeBytes(test, 8);
    indexOutput.writeBytes(test, 5);
    indexOutput.writeByte((byte) 8);
    indexOutput.writeBytes(new byte[] { 1, 2 }, 2);
    indexOutput.close();
}
 
開發者ID:unkascrack,項目名稱:lucene-jdbcdirectory,代碼行數:14,代碼來源:AbstractIndexInputOutputITest.java

示例15: writeBits

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
/** Write as a bit set */
private void writeBits(IndexOutput output) throws IOException {
  output.writeInt(size());        // write size
  output.writeInt(count());       // write count
  output.writeBytes(bits, bits.length);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:BitVector.java


注:本文中的org.apache.lucene.store.IndexOutput.writeInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。