Package org.apache.flink.runtime.io.network.serialization

Examples of org.apache.flink.runtime.io.network.serialization.DataOutputSerializer


  }

  private ByteBuffer serializeEvents(List<? extends AbstractEvent> events) {
    try {
      // create the serialized event list
      DataOutputSerializer serializer = events.size() == 0
        ? new DataOutputSerializer(4)
        : new DataOutputSerializer(events.size() * 32);
      serializer.writeInt(events.size());

      for (AbstractEvent evt : events) {
        serializer.writeUTF(evt.getClass().getName());
        evt.write(serializer);
      }

      return serializer.wrapAsByteBuffer();
    }
    catch (IOException e) {
      throw new RuntimeException("Error while serializing the task events.", e);
    }
  }
View Full Code Here


  @Test
  public void testWrapAsByteBuffer() {
    SerializationTestType randomInt = Util.randomRecord(SerializationTestTypeFactory.INT);

    DataOutputSerializer serializer = new DataOutputSerializer(randomInt.length());
    MemorySegment segment = new MemorySegment(new byte[randomInt.length()]);

    try {
      // empty buffer, read buffer should be empty
      ByteBuffer wrapper = serializer.wrapAsByteBuffer();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(0, wrapper.limit());

      // write to data output, read buffer should still be empty
      randomInt.write(serializer);

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(0, wrapper.limit());

      // get updated read buffer, read buffer should contain written data
      wrapper = serializer.wrapAsByteBuffer();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(randomInt.length(), wrapper.limit());

      // clear data output, read buffer should still contain written data
      serializer.clear();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(randomInt.length(), wrapper.limit());

      // get updated read buffer, should be empty
      wrapper = serializer.wrapAsByteBuffer();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(0, wrapper.limit());

      // write to data output and read back to memory
      randomInt.write(serializer);
      wrapper = serializer.wrapAsByteBuffer();

      segment.put(0, wrapper, randomInt.length());

      Assert.assertEquals(randomInt.length(), wrapper.position());
      Assert.assertEquals(randomInt.length(), wrapper.limit());
View Full Code Here

  @Test
  public void testRandomValuesWriteRead() {
    final int numElements = 100000;
    final ArrayDeque<SerializationTestType> reference = new ArrayDeque<SerializationTestType>();

    DataOutputSerializer serializer = new DataOutputSerializer(1);

    for (SerializationTestType value : Util.randomRecords(numElements)) {
      reference.add(value);

      try {
        value.write(serializer);
      } catch (IOException e) {
        e.printStackTrace();
        Assert.fail("Test encountered an unexpected exception.");
      }
    }

    DataInputDeserializer deserializer = new DataInputDeserializer(serializer.wrapAsByteBuffer());

    for (SerializationTestType expected : reference) {
      try {
        SerializationTestType actual = expected.getClass().newInstance();
        actual.read(deserializer);
View Full Code Here

public class UIDTest {

  //TODO fix with matching DataOutputStream and DataOutputView
  @Test
  public void test() throws IOException {
    DataOutputSerializer out = new DataOutputSerializer(64);
   
    UID id = new UID(3);
    id.write(out);

    ByteBuffer buff = out.wrapAsByteBuffer();

   
    DataInputDeserializer in = new DataInputDeserializer(buff);
   
    UID id2 = new UID();
View Full Code Here

    private void writeHeader() throws IOException {
      // Write out the header and version
      out.write(Server.HEADER.array());

      // Write out the ConnectionHeader
      DataOutputSerializer buf = new DataOutputSerializer(4 + header.getProtocol().getBytes().length + 1);
      header.write(buf);

      // Write out the payload length
      ByteBuffer wrapper = buf.wrapAsByteBuffer();
      int bufLen = wrapper.limit();
      out.writeInt(bufLen);
      out.write(wrapper.array(), 0, bufLen);
    }
View Full Code Here

    public void sendParam(Call call) {
      if (shouldCloseConnection.get()) {
        return;
      }

      DataOutputSerializer d = null;
      try {
        synchronized (this.out) {

          // for serializing the
          // data to be written
          d = new DataOutputSerializer(64);
          // First, write call id to buffer d
          d.writeInt(call.id);
          // Then write RPC data (the actual call) to buffer d
          call.param.write(d);

          ByteBuffer wrapper = d.wrapAsByteBuffer();
          byte[] data = wrapper.array();
          int dataLength = wrapper.limit();
          out.writeInt(dataLength); // first put the data length
          out.write(data, 0, dataLength);// write the data
          out.flush();
View Full Code Here

TOP

Related Classes of org.apache.flink.runtime.io.network.serialization.DataOutputSerializer

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.