Caucho Forums

Caucho Forums (http://forum.caucho.com//index.php)
-   Hessian (http://forum.caucho.com//forumdisplay.php?f=6)
-   -   Encode a map, decode a map (using Hessian) (http://forum.caucho.com//showthread.php?t=32667)

netsql 01-10-2014 12:37 AM

Encode a map, decode a map (using Hessian)
 
This code fails, cut/paste. Please help me encode a map to byte[], and decode a map. (I'll send it myself to server). tia


public static void main(String[] args) throws Exception {
Map row = new HashMap();
row.put("a", 1);
ByteBuffer b = encMap(row);
System.out.println(b);

Map ret = decMap(b);
System.out.println(ret);
}

public static ByteBuffer encMap(Map map) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Hessian2Output out= new Hessian2Output(bos);
Serializer ser = HFac.getSerializerFactory().getSerializer(Map.clas s);
ser.writeObject(map,out);
byte[] b = bos.toByteArray();
out.close();
return ByteBuffer.wrap(b);
}

public static Map<String, Object> decMap(ByteBuffer bb) throws IOException {
InputStream bs = new ByteArrayInputStream(bb.array());
Hessian2Input in = HFac.createHessian2Input(bs);
Deserializer der = HFac.getSerializerFactory().getDeserializer(Map.cl ass);
Map m2 = (Map) der.readMap(in);
in.close();
return m2;
}


All times are GMT. The time now is 04:10 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.