Examples of UnsafeByteArrayInputStream


Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

  @Override
  public V getValue() {
    if (cachedValue != null) {
      return cachedValue; // Return always same instance
    }
    DataInput dis = new UnsafeByteArrayInputStream(valueBytes);
    cachedValue = getConf().createVertexValue();
    try {
      cachedValue.readFields(dis);
    } catch (IOException ioe) {
      throw new RuntimeException("Could not deserialize vertex value", ioe);
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

    assertEquals(0, partition.getEdgeCount());
    assertEquals(7, partition.getVertexCount());
    UnsafeByteArrayOutputStream outputStream = new
        UnsafeByteArrayOutputStream();
    partition.write(outputStream);
    UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(
        outputStream.getByteArray(), 0, outputStream.getPos());
    Partition<IntWritable, IntWritable, NullWritable> deserializatedPartition =
        conf.createPartition(-1, context);
    deserializatedPartition.readFields(inputStream);
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

    long deserializeNanosStart;
    long deserializeNanos = 0;
    for (int i = 0; i < REPS; ++i) {
      deserializeNanosStart = SystemTime.get().getNanoseconds();
      UnsafeByteArrayInputStream inputStream = new
          UnsafeByteArrayInputStream(
          outputStream.getByteArray(), 0, outputStream.getPos());
      WritableUtils.reinitializeVertexFromDataInput(
          inputStream, readVertex, readVertex.getConf());
      deserializeNanos += Times.getNanosecondsSince(SystemTime.get(),
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

   * @return ExtendedDataInput object
   */
  public ExtendedDataInput createExtendedDataInput(
      byte[] buf, int off, int length) {
    if (useUnsafeSerialization) {
      return new UnsafeByteArrayInputStream(buf, off, length);
    } else {
      return new ExtendedByteArrayDataInput(buf, off, length);
    }
  }
View Full Code Here

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

Examples of org.apache.lucene.util.UnsafeByteArrayInputStream

    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

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));

    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

Examples of org.apache.lucene.util.UnsafeByteArrayInputStream

    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

Examples of org.apache.lucene.util.UnsafeByteArrayInputStream

  }

  @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

Examples of org.apache.lucene.util.UnsafeByteArrayInputStream

  }

  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
Copyright © 2018 www.massapi.com. 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.