Examples of UnsafeByteArrayOutputStream


Examples of org.apache.giraph.utils.UnsafeByteArrayOutputStream

    Vertex<LongWritable, FloatWritable, DoubleWritable> vertex =
        buildVertex(edgesClass);

    long serializeNanosStart;
    long serializeNanos = 0;
    UnsafeByteArrayOutputStream outputStream = null;
    for (int i = 0; i <
        REPS; ++i) {
      serializeNanosStart = SystemTime.get().getNanoseconds();
      outputStream =
          new UnsafeByteArrayOutputStream(32);
      WritableUtils.writeVertexToDataOutput(outputStream, vertex, vertex.getConf());
      serializeNanos += Times.getNanosecondsSince(SystemTime.get(),
          serializeNanosStart);
    }
    serializeNanos /= REPS;
    System.out.println("testUnsafeSerializeOutEdgesClass: " +
        "Serializing took " +
        serializeNanos +
        " ns for " + outputStream.getPos()
        + " bytes " +
        (outputStream.getPos() * 1f *
            Time.NS_PER_SECOND / serializeNanos) +
        " bytes / sec for " + edgesClass.getName());

    Vertex<LongWritable, FloatWritable, DoubleWritable>
        readVertex = buildVertex(edgesClass);

    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(),
          deserializeNanosStart);
    }
    deserializeNanos /= REPS;
    System.out.println("testUnsafeSerializeOutEdgesClass: " +
        "Deserializing took " +
        deserializeNanos +
        " ns for " + outputStream.getPos() +
        " bytes " +
        (outputStream.getPos() * 1f *
            Time.NS_PER_SECOND / deserializeNanos) +
        " bytes / sec for " + edgesClass.getName());

    assertEquals(vertex.getId(), readVertex.getId());
    assertEquals(vertex.getValue(), readVertex.getValue());
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayOutputStream

   *
   * @return ExtendedDataOutput object
   */
  public ExtendedDataOutput createExtendedDataOutput() {
    if (useUnsafeSerialization) {
      return new UnsafeByteArrayOutputStream();
    } else {
      return new ExtendedByteArrayDataOutput();
    }
  }
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayOutputStream

   * @param expectedSize Expected size
   * @return ExtendedDataOutput object
   */
  public ExtendedDataOutput createExtendedDataOutput(int expectedSize) {
    if (useUnsafeSerialization) {
      return new UnsafeByteArrayOutputStream(expectedSize);
    } else {
      return new ExtendedByteArrayDataOutput(expectedSize);
    }
  }
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayOutputStream

   * @return ExtendedDataOutput object
   */
  public ExtendedDataOutput createExtendedDataOutput(byte[] buf,
                                                     int pos) {
    if (useUnsafeSerialization) {
      return new UnsafeByteArrayOutputStream(buf, pos);
    } else {
      return new ExtendedByteArrayDataOutput(buf, pos);
    }
  }
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayOutputStream

  public SendAggregatorsToOwnerRequest() {
  }

  @Override
  public void doRequest(ServerData serverData) {
    UnsafeByteArrayOutputStream reusedOut = new UnsafeByteArrayOutputStream();
    UnsafeReusableByteArrayInput reusedIn = new UnsafeReusableByteArrayInput();

    DataInput input = getDataInput();
    AllAggregatorServerData aggregatorData = serverData.getAllAggregatorData();
    try {
View Full Code Here

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

Examples of org.apache.lucene.util.UnsafeByteArrayOutputStream

  @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

Examples of org.apache.lucene.util.UnsafeByteArrayOutputStream

  @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

Examples of org.apache.lucene.util.UnsafeByteArrayOutputStream

  @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

Examples of org.apache.lucene.util.UnsafeByteArrayOutputStream

    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
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.