01: /*
02: * Copyright (C) 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 15. July 2006 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.tools.benchmark.products;
13:
14: import com.thoughtworks.xstream.tools.benchmark.Product;
15: import com.thoughtworks.xstream.XStream;
16: import com.thoughtworks.xstream.io.binary.BinaryStreamWriter;
17: import com.thoughtworks.xstream.io.binary.BinaryStreamReader;
18:
19: import java.io.OutputStream;
20: import java.io.InputStream;
21:
22: /**
23: * Uses XStream with binary format instead of XML.
24: *
25: * @author Joe Walnes
26: * @see com.thoughtworks.xstream.tools.benchmark.Harness
27: * @see Product
28: * @see XStream
29: * @see BinaryStreamReader
30: * @see BinaryStreamWriter
31: */
32: public class XStreamBinary implements Product {
33:
34: private final XStream xstream;
35:
36: public XStreamBinary() {
37: this .xstream = new XStream();
38: }
39:
40: public void serialize(Object object, OutputStream output)
41: throws Exception {
42: xstream.marshal(object, new BinaryStreamWriter(output));
43: }
44:
45: public Object deserialize(InputStream input) throws Exception {
46: return xstream.unmarshal(new BinaryStreamReader(input));
47: }
48:
49: public String toString() {
50: return "XStream (binary format)";
51: }
52:
53: }
|