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


Java IndexOutput.writeByte方法代碼示例

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


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

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

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

示例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_0_2.java

示例4: testOtherFiles

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
public void testOtherFiles() throws Throwable {
  Directory dir = newDirectory();
  IndexWriter iw = new IndexWriter(dir, 
      newIndexWriterConfig(new MockAnalyzer(random())));
  iw.addDocument(new Document());
  iw.close();
  try {
    // Create my own random file:
    IndexOutput out = dir.createOutput("myrandomfile", newIOContext(random()));
    out.writeByte((byte) 42);
    out.close();
    
    new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))).close();
    
    assertTrue(slowFileExists(dir, "myrandomfile"));
  } finally {
    dir.close();
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:20,代碼來源:TestIndexWriter.java

示例5: testVerifyingIndexOutputWithBogusInput

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
public void testVerifyingIndexOutputWithBogusInput() throws IOException {
    Directory dir = newDirectory();
    int length = scaledRandomIntBetween(10, 1024);
    IndexOutput verifyingOutput = new Store.LuceneVerifyingIndexOutput(new StoreFileMetaData("foo1.bar", length, ""), dir.createOutput("foo1.bar", IOContext.DEFAULT));
    try {
        while (length > 0) {
            verifyingOutput.writeByte((byte) random().nextInt());
            length--;
        }
        fail("should be a corrupted index");
    } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
        // ok
    }
    IOUtils.close(verifyingOutput, dir);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:StoreTests.java

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

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

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

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

示例10: addBytesField

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

示例11: createRandomFile

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
/** Creates a file of the specified size with random data. */
private void createRandomFile(Directory dir, String name, int size)
throws IOException
{
    IndexOutput os = dir.createOutput(name, newIOContext(random()));
    for (int i=0; i<size; i++) {
        byte b = (byte) (Math.random() * 256);
        os.writeByte(b);
    }
    os.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:12,代碼來源:TestCompoundFile.java

示例12: createSequenceFile

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
/** Creates a file of the specified size with sequential data. The first
 *  byte is written as the start byte provided. All subsequent bytes are
 *  computed as start + offset where offset is the number of the byte.
 */
private void createSequenceFile(Directory dir,
                                String name,
                                byte start,
                                int size)
throws IOException
{
    IndexOutput os = dir.createOutput(name, newIOContext(random()));
    for (int i=0; i < size; i++) {
        os.writeByte(start);
        start ++;
    }
    os.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:18,代碼來源:TestCompoundFile.java

示例13: demo_FSIndexInputBug

import org.apache.lucene.store.IndexOutput; //導入方法依賴的package包/類
private void demo_FSIndexInputBug(Directory fsdir, String file)
throws IOException
{
    // Setup the test file - we need more than 1024 bytes
    IndexOutput os = fsdir.createOutput(file, IOContext.DEFAULT);
    for(int i=0; i<2000; i++) {
        os.writeByte((byte) i);
    }
    os.close();

    IndexInput in = fsdir.openInput(file, IOContext.DEFAULT);

    // This read primes the buffer in IndexInput
    in.readByte();

    // Close the file
    in.close();

    // ERROR: this call should fail, but succeeds because the buffer
    // is still filled
    in.readByte();

    // ERROR: this call should fail, but succeeds for some reason as well
    in.seek(1099);

    try {
        // OK: this call correctly fails. We are now past the 1024 internal
        // buffer, so an actual IO is attempted, which fails
        in.readByte();
        fail("expected readByte() to throw exception");
    } catch (IOException e) {
      // expected exception
    }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:35,代碼來源:TestCompoundFile.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.writeByte方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。