01: /*
02: * Copyright (C) 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007, 2008 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 22. June 2006 by Mauro Talevi
11: */
12: package com.thoughtworks.xstream.io.json;
13:
14: import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
15: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17: import com.thoughtworks.xstream.io.StreamException;
18:
19: import java.io.InputStream;
20: import java.io.OutputStream;
21: import java.io.OutputStreamWriter;
22: import java.io.Reader;
23: import java.io.UnsupportedEncodingException;
24: import java.io.Writer;
25:
26: /**
27: * @author Paul Hammant
28: * @since 1.2
29: */
30: public class JsonHierarchicalStreamDriver implements
31: HierarchicalStreamDriver {
32: public HierarchicalStreamReader createReader(Reader in) {
33: throw new UnsupportedOperationException(
34: "The JsonHierarchicalStreamDriver can only write JSON");
35: }
36:
37: public HierarchicalStreamReader createReader(InputStream in) {
38: throw new UnsupportedOperationException(
39: "The JsonHierarchicalStreamDriver can only write JSON");
40: }
41:
42: public HierarchicalStreamWriter createWriter(Writer out) {
43: return new JsonHierarchicalStreamWriter(out);
44: }
45:
46: public HierarchicalStreamWriter createWriter(OutputStream out) {
47: try {
48: // JSON spec requires UTF-8
49: return createWriter(new OutputStreamWriter(out, "UTF-8"));
50: } catch (UnsupportedEncodingException e) {
51: throw new StreamException(e);
52: }
53: }
54:
55: }
|