コード例 #1
0
  public void testSerialiser() throws Exception {
    SerialisableHashMap map = new SerialisableHashMap();
    map.put("one", new Integer(1));
    map.put(map, null);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BinarySerialiserStream bss = new BinarySerialiserStream(output);
    bss.writeObject(map);
    bss.flush();

    System.out.println(new String(output.toByteArray()));

    ByteArrayInputBuffer input = new ByteArrayInputBuffer(output.toByteArray());
    BinaryDeserialiserStream bds = new BinaryDeserialiserStream(new SimpleClassLoader(), input);

    System.out.println(bds.readObject());
  }
コード例 #2
0
  public void testCachedSerialiser() throws Exception {
    ReferenceCache rc = new ReferenceCache();
    rc.cacheReference(SerialisableHashMap.class.getName());

    SerialisableHashMap map = new SerialisableHashMap();
    map.put("one", new Integer(1));
    map.put(map, null);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BinarySerialiserStream bss = rc.createSerialiser(output);
    bss.writeObject(map);
    bss.flush();

    System.out.println(new String(output.toByteArray()));

    ByteArrayInputBuffer input = new ByteArrayInputBuffer(output.toByteArray());
    BinaryDeserialiserStream bds = rc.createDeserialiser(new SimpleClassLoader(), input);

    System.out.println(bds.readObject());
  }