01: package sisc.io;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.InputStream;
05: import java.io.InputStreamReader;
06: import java.io.OutputStream;
07: import java.io.OutputStreamWriter;
08: import java.io.UnsupportedEncodingException;
09:
10: /**
11: * Wrapper class which names a Character Set
12: *
13: * @author scgmille
14: *
15: */
16: public class Charset {
17:
18: private String name;
19:
20: public static Charset forName(String name)
21: throws UnsupportedEncodingException {
22: new InputStreamReader(new ByteArrayInputStream(new byte[0]),
23: name);
24: Charset cs = new Charset();
25: cs.name = name;
26: return cs;
27: }
28:
29: public String getName() {
30: return name;
31: }
32:
33: public String displayName() {
34: return name;
35: }
36:
37: public InputStreamReader newInputStreamReader(InputStream in) {
38: try {
39: return new InputStreamReader(in, getName());
40: } catch (UnsupportedEncodingException use) {
41: //Can't happen
42: return null;
43: }
44: }
45:
46: public OutputStreamWriter newOutputStreamWriter(OutputStream out) {
47: try {
48: return new OutputStreamWriter(out, getName());
49: } catch (UnsupportedEncodingException use) {
50: //Can't happen
51: return null;
52: }
53: }
54: }
55: /*
56: * The contents of this file are subject to the Mozilla Public
57: * License Version 1.1 (the "License"); you may not use this file
58: * except in compliance with the License. You may obtain a copy of
59: * the License at http://www.mozilla.org/MPL/
60: *
61: * Software distributed under the License is distributed on an "AS
62: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
63: * implied. See the License for the specific language governing
64: * rights and limitations under the License.
65: *
66: * The Original Code is the Second Interpreter of Scheme Code (SISC).
67: *
68: * The Initial Developer of the Original Code is Scott G. Miller.
69: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
70: * Scott G. Miller. All Rights Reserved.
71: *
72: * Contributor(s):
73: * Matthias Radestock
74: *
75: * Alternatively, the contents of this file may be used under the
76: * terms of the GNU General Public License Version 2 or later (the
77: * "GPL"), in which case the provisions of the GPL are applicable
78: * instead of those above. If you wish to allow use of your
79: * version of this file only under the terms of the GPL and not to
80: * allow others to use your version of this file under the MPL,
81: * indicate your decision by deleting the provisions above and
82: * replace them with the notice and other provisions required by
83: * the GPL. If you do not delete the provisions above, a recipient
84: * may use your version of this file under either the MPL or the
85: * GPL.
86: */
|