01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package test.javax.management.compliance.serialization.support;
10:
11: import java.io.ByteArrayInputStream;
12: import java.io.ByteArrayOutputStream;
13: import java.io.IOException;
14: import java.io.ObjectInputStream;
15: import java.io.ObjectOutputStream;
16:
17: /**
18: * @version $Revision: 1.4 $
19: */
20: public class Serializer {
21: public byte[] serialize(Object object) throws IOException {
22: ByteArrayOutputStream baos = new ByteArrayOutputStream();
23: ObjectOutputStream oos = new ObjectOutputStream(baos);
24: oos.writeObject(object);
25: oos.close();
26: byte[] bytes = baos.toByteArray();
27: return bytes;
28: }
29:
30: public Object deserialize(byte[] bytes) throws IOException,
31: ClassNotFoundException {
32: ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
33: ObjectInputStream ois = new ObjectInputStream(bais);
34: Object object = ois.readObject();
35: ois.close();
36: return object;
37: }
38: }
|