1
16
17
20
21 package org.apache.wsrp4j.producer.util;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.IOException;
25 import java.io.ObjectInputStream;
26 import java.util.Map;
27
28 import org.apache.wsrp4j.log.LogManager;
29 import org.apache.wsrp4j.log.Logger;
30
31
37 public class ObjectDeserializer {
38
39 private static Logger logger = LogManager.getLogManager().getLogger(
41 ObjectDeserializer.class);
42
43 public static Object deserialize(byte[] map) throws IOException,
44 ClassNotFoundException {
45
46 String MN = "deserialize(byte[])";
47 if (logger.isLogging(Logger.TRACE_HIGH)) {
48 logger.entry(Logger.TRACE_HIGH, MN, map);
49 }
50
51 ByteArrayInputStream bytes = new ByteArrayInputStream(map);
52 ObjectInputStream in = new ObjectInputStream(bytes);
53 Object obj = in.readObject();
54 in.close();
55
56 if (logger.isLogging(Logger.TRACE_HIGH)) {
57 logger.exit(Logger.TRACE_HIGH, MN, obj);
58 }
59
60 return obj;
61 }
62
63 public static Map deserializeMap(byte[] map) throws IOException,
64 ClassNotFoundException {
65 Object obj = deserialize(map);
66
67 String MN = "deserializeMap";
68 if (!(obj instanceof Map)) {
69 obj = null;
70 logger.text(Logger.ERROR, MN, "Deserialized object is not a map.",
71 obj);
72 }
73
74 return (Map) obj;
75 }
76
77 public static String deserializeString(byte[] string) throws IOException,
78 ClassNotFoundException {
79 return (String) deserialize(string);
80 }
81 }