Package marauroa.common.net

Examples of marauroa.common.net.OutputSerializer


   * @throws IOException
   */
  @Test
  public void testSerialization() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputSerializer os = new OutputSerializer(out);

    os.write(obj);

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    InputSerializer is = new InputSerializer(in);

    RPObject result = (RPObject) is.readObject(new RPObject());
View Full Code Here


    RPObject rpo = new RPObject();
    rpo.setRPClass(cls);
    rpo.put("map1", "key11", "value11");
    rpo.put("map1", "key12", "value12");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputSerializer os = new OutputSerializer(out);
    os.write(rpo);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    InputSerializer is = new InputSerializer(in);
    RPObject result = (RPObject) is.readObject(new RPObject());
    assertEquals(rpo, result);
  }
View Full Code Here

    rpo.put("map1", "key11", "value11");
    rpo.put("map1", "key12", "value12");
    rpo.put("map2", "key21", "value21");
    rpo.put("map2", "key22", "value22");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputSerializer os = new OutputSerializer(out);
    os.write(rpo);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    InputSerializer is = new InputSerializer(in);
    RPObject result = (RPObject) is.readObject(new RPObject());
    assertEquals(rpo, result);
  }
View Full Code Here

   * @throws SQLException in case of an database error
   */
  public int storeRPObject(DBTransaction transaction, RPObject object) throws IOException, SQLException {
    ByteArrayOutputStream array = new ByteArrayOutputStream();
    DeflaterOutputStream out_stream = new DeflaterOutputStream(array);
    OutputSerializer serializer = new OutputSerializer(out_stream);
    int protocolVersion = serializer.getProtocolVersion();

    try {
      object.writeObject(serializer, DetailLevel.FULL);
      out_stream.close();
    } catch (IOException e) {
View Full Code Here

      throw new SQLException("Invalid string zoneid=(" + zoneid + ")");
    }

    ByteArrayOutputStream array = new ByteArrayOutputStream();
    DeflaterOutputStream out_stream = new DeflaterOutputStream(array);
    OutputSerializer os = new OutputSerializer(out_stream);

    /* compute how many storable objects exists in zone. */
    int amount = 0;
    for (RPObject object : content) {
      if (object.isStorable()) {
        amount++;
      }
    }

    os.write(amount);

    boolean empty = true;
    for (RPObject object : content) {
      if (object.isStorable()) {
        object.writeObject(os, DetailLevel.FULL);
        empty = false;
      }
    }

    out_stream.close();

    /* Setup the stream for a blob */
    ByteArrayInputStream inStream = new ByteArrayInputStream(array.toByteArray());

    String query;

    if (hasRPZone(transaction, zone.getID())) {
      query = "update rpzone set data=?, protocol_version=[protocolVersion] where zone_id='[zoneid]'";
    } else {
      // do not add empty zones
      if (empty) {
        return;
      }
      query = "insert into rpzone(zone_id, data, protocol_version) values('[zoneid]', ?, [protocolVersion])";
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("zoneid", zoneid);
    params.put("protocolVersion", os.getProtocolVersion());
    logger.debug("storeRPZone is executing query " + query);

    transaction.execute(query, params, inStream);
  }
View Full Code Here

  public void writeObject(marauroa.common.net.OutputSerializer out) throws IOException {
    super.writeObject(out);

    ByteArrayOutputStream array = new ByteArrayOutputStream();
    DeflaterOutputStream out_stream = new DeflaterOutputStream(array);
    OutputSerializer serializer = new OutputSerializer(out_stream);
    serializer.setProtocolVersion(out.getProtocolVersion());

    serializer.write(contents);
    int size = RPClass.size();

    // sort out the default rp class if it is there
    for (Iterator<RPClass> it = RPClass.iterator(); it.hasNext();) {
      RPClass rp_class = it.next();
      if ("".equals(rp_class.getName())) {
        size--;
        break;
      }
    }

    serializer.write(size);
    for (Iterator<RPClass> it = RPClass.iterator(); it.hasNext();) {
      RPClass rp_class = it.next();
      if (!"".equals(rp_class.getName())) // sort out default class if it
      // is there
      {
        serializer.write(rp_class);
      }
    }

    out_stream.close();
View Full Code Here

  @Test
  public final void testReadWriteObject() throws IOException {
    MockMessage mmOut = new MockMessage(MessageType.C2S_ACTION, SocketChannel.open());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mmOut.setClientID(1);
    mmOut.writeObject(new OutputSerializer(out));
    InputSerializer in = new InputSerializer(new ByteArrayInputStream(out.toByteArray()));
    MockMessage mmInn = new MockMessage(MessageType.C2S_ACTION, SocketChannel.open());

    mmInn.readObject(in);
    assertEquals(mmOut.getClientID(), mmInn.getClientID());
View Full Code Here

  @Test
  public final void testInvalidClientId() throws IOException {
    MockMessage mmOut = new MockMessage(MessageType.C2S_ACTION, SocketChannel.open());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mmOut.setClientID(Message.CLIENTID_INVALID);
    mmOut.writeObject(new OutputSerializer(out));
    InputSerializer in = new InputSerializer(new ByteArrayInputStream(out.toByteArray()));
    MockMessage mmInn = new MockMessage(MessageType.C2S_ACTION, SocketChannel.open());

    mmInn.readObject(in);
    assertEquals(mmOut.getClientID(), mmInn.getClientID());
View Full Code Here

    tcInn.cacheable=true;
    tcInn.data=new byte[64];
   
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    tcInn.writeREQ(new OutputSerializer(out));
    InputSerializer in = new InputSerializer(new ByteArrayInputStream(out.toByteArray()));

    TransferContent tcOut = new TransferContent();
    tcOut.readREQ(in);
    assertTrue(tcInn.ack == tcOut.ack);
View Full Code Here

    tcInn.cacheable=true;
    tcInn.data=new byte[64];

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    tcInn.writeACK(new OutputSerializer(out));
    InputSerializer in = new InputSerializer(new ByteArrayInputStream(out.toByteArray()));

    TransferContent tcOut = new TransferContent();
    tcOut.readACK(in);
    assertTrue(tcInn.ack == tcOut.ack);
View Full Code Here

TOP

Related Classes of marauroa.common.net.OutputSerializer

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.