Package org.apache.lucene.store

Examples of org.apache.lucene.store.DataOutput


  /**
   * Calls {@link #store(DataOutput)} after converting
   * {@link OutputStream} to {@link DataOutput}
   */
  public boolean store(OutputStream output) throws IOException {
    DataOutput dataOut = new OutputStreamDataOutput(output);
    try {
      return store(dataOut);
    } finally {
      IOUtils.close(output);
    }
View Full Code Here


  public void testDataInputOutput() throws Exception {
    for(int iter=0;iter<5*RANDOM_MULTIPLIER;iter++) {
      final int blockBits = _TestUtil.nextInt(random, 1, 20);
      final int blockSize = 1 << blockBits;
      final PagedBytes p = new PagedBytes(blockBits);
      final DataOutput out = p.getDataOutput();
      final int numBytes = random.nextInt(10000000);

      final byte[] answer = new byte[numBytes];
      random.nextBytes(answer);
      int written = 0;
      while(written < numBytes) {
        if (random.nextInt(10) == 7) {
          out.writeByte(answer[written++]);
        } else {
          int chunk = Math.min(random.nextInt(1000), numBytes - written);
          out.writeBytes(answer, written, chunk);
          written += chunk;
        }
      }

      final PagedBytes.Reader reader = p.freeze(random.nextBoolean());
View Full Code Here

  // copyUsingLengthPrefix will never span two blocks, make
  // sure if caller writes their own prefix followed by the
  // bytes, it still works:
  public void testLengthPrefixAcrossTwoBlocks() throws Exception {
    final PagedBytes p = new PagedBytes(10);
    final DataOutput out = p.getDataOutput();
    final byte[] bytes1 = new byte[1000];
    random.nextBytes(bytes1);
    out.writeBytes(bytes1, 0, bytes1.length);
    out.writeByte((byte) 40);
    final byte[] bytes2 = new byte[40];
    random.nextBytes(bytes2);
    out.writeBytes(bytes2, 0, bytes2.length);

    final PagedBytes.Reader reader = p.freeze(random.nextBoolean());
    BytesRef answer = reader.fillSliceWithPrefix(new BytesRef(), 1000);
    assertEquals(40, answer.length);
    for(int i=0;i<40;i++) {
View Full Code Here

      ConnectionCosts.class.getName().replace('.', File.separatorChar) + ConnectionCosts.FILENAME_SUFFIX;
    new File(filename).getParentFile().mkdirs();
    OutputStream os = new FileOutputStream(filename);
    try {
      os = new BufferedOutputStream(os);
      final DataOutput out = new OutputStreamDataOutput(os);
      CodecUtil.writeHeader(out, ConnectionCosts.HEADER, ConnectionCosts.VERSION);
      out.writeVInt(forwardSize);
      out.writeVInt(backwardSize);
      int last = 0;
      assert costs.length == backwardSize;
      for (short[] a : costs) {
        assert a.length == forwardSize;
        for (int i = 0; i < a.length; i++) {
          int delta = (int)a[i] - last;
          out.writeVInt((delta >> 31) ^ (delta << 1));
          last = a[i];
        }
      }
    } finally {
      os.close();
View Full Code Here

  protected void writeTargetMap(String filename) throws IOException {
    new File(filename).getParentFile().mkdirs();
    OutputStream os = new FileOutputStream(filename);
    try {
      os = new BufferedOutputStream(os);
      final DataOutput out = new OutputStreamDataOutput(os);
      CodecUtil.writeHeader(out, BinaryDictionary.TARGETMAP_HEADER, BinaryDictionary.VERSION);
     
      final int numSourceIds = lastSourceId + 1;
      out.writeVInt(targetMapEndOffset); // <-- size of main array
      out.writeVInt(numSourceIds + 1); // <-- size of offset array (+ 1 more entry)
      int prev = 0, sourceId = 0;
      for (int ofs = 0; ofs < targetMapEndOffset; ofs++) {
        final int val = targetMap[ofs], delta = val - prev;
        assert delta >= 0;
        if (ofs == targetMapOffsets[sourceId]) {
          out.writeVInt((delta << 1) | 0x01);
          sourceId++;
        } else {
          out.writeVInt((delta << 1));
        }
        prev += delta;
      }
      assert sourceId == numSourceIds : "sourceId:"+sourceId+" != numSourceIds:"+numSourceIds;
    } finally {
View Full Code Here

  protected void writePosDict(String filename) throws IOException {
    new File(filename).getParentFile().mkdirs();
    OutputStream os = new FileOutputStream(filename);
    try {
      os = new BufferedOutputStream(os);
      final DataOutput out = new OutputStreamDataOutput(os);
      CodecUtil.writeHeader(out, BinaryDictionary.POSDICT_HEADER, BinaryDictionary.VERSION);
      out.writeVInt(posDict.size());
      for (String s : posDict) {
        if (s == null) {
          out.writeByte((byte)0);
          out.writeByte((byte)0);
          out.writeByte((byte)0);
        } else {
          String data[] = CSVUtil.parse(s);
          assert data.length == 3 : "malformed pos/inflection: " + s;
          out.writeString(data[0]);
          out.writeString(data[1]);
          out.writeString(data[2]);
        }
      }
    } finally {
      os.close();
    }
View Full Code Here

 
  protected void writeDictionary(String filename) throws IOException {
    new File(filename).getParentFile().mkdirs();
    final FileOutputStream os = new FileOutputStream(filename);
    try {
      final DataOutput out = new OutputStreamDataOutput(os);
      CodecUtil.writeHeader(out, BinaryDictionary.DICT_HEADER, BinaryDictionary.VERSION);
      out.writeVInt(buffer.position());
      final WritableByteChannel channel = Channels.newChannel(os);
      // Write Buffer
      buffer.flip()// set position to 0, set limit to current position
      channel.write(buffer);
      assert buffer.remaining() == 0L;
View Full Code Here

      CharacterDefinition.class.getName().replace('.', File.separatorChar) + CharacterDefinition.FILENAME_SUFFIX;
    new File(filename).getParentFile().mkdirs();
    OutputStream os = new FileOutputStream(filename);
    try {
      os = new BufferedOutputStream(os);
      final DataOutput out = new OutputStreamDataOutput(os);
      CodecUtil.writeHeader(out, CharacterDefinition.HEADER, CharacterDefinition.VERSION);
      out.writeBytes(characterCategoryMap, 0, characterCategoryMap.length);
      for (int i = 0; i < CharacterDefinition.CLASS_COUNT; i++) {
        final byte b = (byte) (
          (invokeMap[i] ? 0x01 : 0x00) |
          (groupMap[i] ? 0x02 : 0x00)
        );
        out.writeByte(b);
      }
    } finally {
      os.close();
    }
  }
View Full Code Here

public class TestPagedBytes extends LuceneTestCase {

  public void testDataInputOutput() throws Exception {
    for(int iter=0;iter<5*RANDOM_MULTIPLIER;iter++) {
      final PagedBytes p = new PagedBytes(_TestUtil.nextInt(random, 1, 20));
      final DataOutput out = p.getDataOutput();
      final int numBytes = random.nextInt(10000000);

      final byte[] answer = new byte[numBytes];
      random.nextBytes(answer);
      int written = 0;
      while(written < numBytes) {
        if (random.nextInt(10) == 7) {
          out.writeByte(answer[written++]);
        } else {
          int chunk = Math.min(random.nextInt(1000), numBytes - written);
          out.writeBytes(answer, written, chunk);
          written += chunk;
        }
      }

      p.freeze(random.nextBoolean());
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.DataOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.