Package org.apache.lucene.util

Examples of org.apache.lucene.util.UnsafeByteArrayOutputStream


  @Test
  public void testSimpleWrite() throws IOException {
    int length = 100;
    byte[] buffer = new byte[length];
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream(buffer);

    for (int i = 0; i < 100; i++) {
      ubaos.write((byte) i);
    }

    byte[] result = ubaos.toByteArray();

    assertEquals(length, ubaos.length());

    for (int j = 0; j < length; ++j) {
      assertEquals(result[j], j);
    }
  }
View Full Code Here


  @Test
  public void testArrayWrite() throws IOException {
    int length = 100;
    byte[] buffer = new byte[length];
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream(buffer);

    for (int i = 0; i < 100; i++) {
      ubaos.write((byte) i);
    }

    int length2 = 10;
    byte[] buffer2 = new byte[length2];
    for (int i = 0; i < length2; i++) {
      buffer2[i] = (byte) (8 + i);
    }

    ubaos.write(buffer2);

    byte[] result = ubaos.toByteArray();

    assertEquals(length + length2, ubaos.length());

    for (int j = 0; j < length; ++j) {
      assertEquals(result[j], j);
    }
    for (int j = 0; j < length2; ++j) {
View Full Code Here

  @Test
  public void testArrayWriteStartNotZero() throws IOException {
    int length = 100;
    byte[] buffer = new byte[length];
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream(buffer);

    for (int i = 0; i < 100; i++) {
      ubaos.write((byte) i);
    }

    int length2 = 1000;
    byte[] buffer2 = new byte[length2];
    for (int i = 0; i < length2; i++) {
      buffer2[i] = (byte) (8 + i);
    }

    int length3 = 5;
    int start = 2;
    ubaos.write(buffer2, start, length3);

    byte[] result = ubaos.toByteArray();

    assertEquals(length + length3, ubaos.length());

    for (int j = 0; j < length; ++j) {
      assertEquals(result[j], j);
    }
    for (int j = 0; j < length3; ++j) {
View Full Code Here

  @Test
  public void testBufferGrow() throws IOException {
    int length = 100;
    byte[] buffer = new byte[length / 10];
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream(buffer);

    for (int i = 0; i < length; i++) {
      ubaos.write((byte) i);
    }

    byte[] result = ubaos.toByteArray();

    assertEquals(length, ubaos.length());

    for (int j = 0; j < length; ++j) {
      assertEquals(result[j], j);
    }

    buffer = ubaos.toByteArray();

    int length2 = 10;
    byte[] buffer2 = new byte[length2];
    for (int i = 0; i < length2; i++) {
      buffer2[i] = (byte) (8 + i);
    }

    ubaos.reInit(buffer2);
    for (int i = 0; i < length2; i++) {
      ubaos.write(7 + i);
    }

    byte[] result2 = ubaos.toByteArray();

    assertEquals(length2, ubaos.length());

    for (int j = 0; j < length2; ++j) {
      assertEquals(result2[j], j + 7);
    }
View Full Code Here

    for (int i = 0; i < buf.length; i++) {
      buf[i] = (byte) i;
    }
   
    int startPos = 3;
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream(buf, startPos);
    int numValues = 5;
    for (int i = 0; i < numValues; i++) {
      ubaos.write((i + 1) * 2);
    }

    // the length of the buffer should be whatever was written after startPos
    // and before that.
    assertEquals("invalid buffer length", startPos + numValues, ubaos.length());

    assertEquals("invalid startPos", startPos, ubaos.getStartPos());

    byte[] bytes = ubaos.toByteArray();
    for (int i = 0; i < startPos; i++) {
      assertEquals(i, bytes[i]);
    }
   
    for (int i = startPos, j = 0; j < numValues; i++, j++) {
View Full Code Here

  }

  @Test
  public void testDefaultCtor() throws Exception {
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream();
    int numValues = 5;
    for (int i = 0; i < numValues; i++) {
      ubaos.write(i);
    }

    assertEquals("invalid buffer length", numValues, ubaos.length());
   
    byte[] bytes = ubaos.toByteArray();
    for (int i = 0; i < numValues; i++) {
      assertEquals(i, bytes[i]);
    }
  }
View Full Code Here

    }
  }
 
  @Test(expected=IllegalArgumentException.class)
  public void testIllegalBufferSize() throws Exception {
    UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream();
    ubaos.reInit(new byte[0]);
  }
View Full Code Here

TOP

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

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.