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.xml.XppDriver;
17: import com.thoughtworks.xstream.io.xml.CompactWriter;
18:
19: import java.io.OutputStream;
20: import java.io.InputStream;
21: import java.io.OutputStreamWriter;
22:
23: /**
24: * Uses XStream with a compact XML output format.
25: *
26: * @author Joe Walnes
27: * @see com.thoughtworks.xstream.tools.benchmark.Harness
28: * @see Product
29: * @see XStream
30: * @see CompactWriter
31: */
32: public class XStreamCompact implements Product {
33:
34: private final XStream xstream;
35:
36: public XStreamCompact() {
37: this .xstream = new XStream(new XppDriver());
38: }
39:
40: public void serialize(Object object, OutputStream output)
41: throws Exception {
42: xstream.marshal(object, new CompactWriter(
43: new OutputStreamWriter(output)));
44: }
45:
46: public Object deserialize(InputStream input) throws Exception {
47: return xstream.fromXML(input);
48: }
49:
50: public String toString() {
51: return "XStream (Compact XML)";
52: }
53:
54: }
|