Package org.apache.lucene.util

Examples of org.apache.lucene.util.UnsafeByteArrayInputStream


    byte[] buffer = new byte[length];
    for (int i = 0; i < length; ++i) {
      buffer[i] = (byte) i;
    }
    byte[] result = new byte[buffer.length];
    UnsafeByteArrayInputStream ubais = new UnsafeByteArrayInputStream(buffer);
   
    int index = 0;
    int by = ubais.read();
    while (by >= 0) {
      result[index++] = (byte) (by);
      by = ubais.read();
    }
   
    assertEquals(length, index);
    assertTrue(Arrays.equals(buffer, result));
  }
View Full Code Here


    for (int i = 0; i < length; ++i) {
      buffer[i] = (byte) i;
    }
    int startPos = 5;
    byte[] result = new byte[buffer.length];
    UnsafeByteArrayInputStream ubais = new UnsafeByteArrayInputStream(buffer, startPos, length);
   
    int index = 0;
    int by = ubais.read();
    while (by >= 0) {
      result[index++] = (byte) (by);
      by = ubais.read();
    }
   
    assertEquals(length - startPos, index);
    for (int i = startPos; i < length; i++) {
      assertEquals(buffer[i], result[i - startPos]);
View Full Code Here

    byte[] buffer = new byte[length];
    for (int i = 0; i < length; ++i) {
      buffer[i] = (byte) i;
    }
    byte[] result = new byte[buffer.length];
    UnsafeByteArrayInputStream ubais = new UnsafeByteArrayInputStream(buffer);

    int index = 0;
    int by = ubais.read();
    while (by >= 0) {
      result[index++] = (byte) (by);
      by = ubais.read();
    }

    assertEquals(length, index);
    assertTrue(Arrays.equals(buffer, result));

    int length2 = 50;
    byte[] buffer2 = new byte[length2];
    for (int i = 0; i < length2; ++i) {
      buffer2[i] = (byte) (90 + i);
    }
    byte[] result2 = new byte[buffer2.length];
    ubais.reInit(buffer2);

    int index2 = 0;
    int by2 = ubais.read();
    while (by2 >= 0) {
      result2[index2++] = (byte) (by2);
      by2 = ubais.read();
    }

    assertEquals(length2, index2);
    assertTrue(Arrays.equals(buffer2, result2));
  }
View Full Code Here

    assertTrue(Arrays.equals(buffer2, result2));
  }

  @Test
  public void testDefaultCtor() throws Exception {
    UnsafeByteArrayInputStream ubais = new UnsafeByteArrayInputStream();
    assertEquals(0, ubais.available());
    assertEquals(-1, ubais.read());
  }
View Full Code Here

  }

  @Test
  public void testMark() throws Exception {
    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    UnsafeByteArrayInputStream ubais = new UnsafeByteArrayInputStream(bytes);
    assertTrue(ubais.markSupported());
    int markIndex = 3;
    // Advance the index
    for (int i = 0; i < markIndex; i++) {
      ubais.read();
    }
    ubais.mark(markIndex);
    for (int i = markIndex; i < bytes.length; i++) {
      ubais.read();
    }
    ubais.reset();
    assertEquals(bytes.length - markIndex, ubais.available());
  }
View Full Code Here

  }

  public PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder,
                                    byte[] buffer) throws IOException {
    pi = new PayloadIterator(indexReader, term, buffer);
    ubais = new UnsafeByteArrayInputStream();
    this.decoder = decoder;
    hashCode = indexReader.hashCode() ^ term.hashCode();
    this.term = term;
    this.indexReader = indexReader;
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.UnsafeByteArrayInputStream

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.