1 | /* |
---|
2 | * CaseFrobStream.java |
---|
3 | * |
---|
4 | * Copyright (C) 2004 Peter Graves |
---|
5 | * $Id: CaseFrobStream.java 11488 2008-12-27 10:50:33Z ehuelsmann $ |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
20 | * |
---|
21 | * As a special exception, the copyright holders of this library give you |
---|
22 | * permission to link this library with independent modules to produce an |
---|
23 | * executable, regardless of the license terms of these independent |
---|
24 | * modules, and to copy and distribute the resulting executable under |
---|
25 | * terms of your choice, provided that you also meet, for each linked |
---|
26 | * independent module, the terms and conditions of the license of that |
---|
27 | * module. An independent module is a module which is not derived from |
---|
28 | * or based on this library. If you modify this library, you may extend |
---|
29 | * this exception to your version of the library, but you are not |
---|
30 | * obligated to do so. If you do not wish to do so, delete this |
---|
31 | * exception statement from your version. |
---|
32 | */ |
---|
33 | |
---|
34 | package org.armedbear.lisp; |
---|
35 | |
---|
36 | public abstract class CaseFrobStream extends Stream |
---|
37 | { |
---|
38 | protected final Stream target; |
---|
39 | |
---|
40 | protected CaseFrobStream(Stream target) |
---|
41 | throws ConditionThrowable |
---|
42 | { |
---|
43 | Debug.assertTrue(target.isCharacterOutputStream()); |
---|
44 | this.target = target; |
---|
45 | } |
---|
46 | |
---|
47 | @Override |
---|
48 | public LispObject getElementType() throws ConditionThrowable |
---|
49 | { |
---|
50 | return target.getElementType(); |
---|
51 | } |
---|
52 | |
---|
53 | @Override |
---|
54 | public LispObject typeOf() |
---|
55 | { |
---|
56 | return Symbol.CASE_FROB_STREAM; |
---|
57 | } |
---|
58 | |
---|
59 | @Override |
---|
60 | public LispObject classOf() |
---|
61 | { |
---|
62 | return BuiltInClass.CASE_FROB_STREAM; |
---|
63 | } |
---|
64 | |
---|
65 | @Override |
---|
66 | public LispObject typep(LispObject type) throws ConditionThrowable |
---|
67 | { |
---|
68 | if (type == Symbol.CASE_FROB_STREAM) |
---|
69 | return T; |
---|
70 | if (type == BuiltInClass.CASE_FROB_STREAM) |
---|
71 | return T; |
---|
72 | return super.typep(type); |
---|
73 | } |
---|
74 | |
---|
75 | @Override |
---|
76 | public boolean isInputStream() |
---|
77 | { |
---|
78 | return false; |
---|
79 | } |
---|
80 | |
---|
81 | @Override |
---|
82 | public boolean isOutputStream() |
---|
83 | { |
---|
84 | return true; |
---|
85 | } |
---|
86 | |
---|
87 | @Override |
---|
88 | public boolean isCharacterInputStream() throws ConditionThrowable |
---|
89 | { |
---|
90 | return false; |
---|
91 | } |
---|
92 | |
---|
93 | @Override |
---|
94 | public boolean isBinaryInputStream() throws ConditionThrowable |
---|
95 | { |
---|
96 | return false; |
---|
97 | } |
---|
98 | |
---|
99 | @Override |
---|
100 | public boolean isCharacterOutputStream() throws ConditionThrowable |
---|
101 | { |
---|
102 | return true; |
---|
103 | } |
---|
104 | |
---|
105 | @Override |
---|
106 | public boolean isBinaryOutputStream() throws ConditionThrowable |
---|
107 | { |
---|
108 | return false; |
---|
109 | } |
---|
110 | |
---|
111 | @Override |
---|
112 | public int getCharPos() |
---|
113 | { |
---|
114 | return target.getCharPos(); |
---|
115 | } |
---|
116 | |
---|
117 | @Override |
---|
118 | public void setCharPos(int n) |
---|
119 | { |
---|
120 | target.setCharPos(n); |
---|
121 | } |
---|
122 | |
---|
123 | // Returns -1 at end of file. |
---|
124 | @Override |
---|
125 | protected int _readChar() throws ConditionThrowable |
---|
126 | { |
---|
127 | notSupported(); |
---|
128 | // Not reached. |
---|
129 | return -1; |
---|
130 | } |
---|
131 | |
---|
132 | @Override |
---|
133 | protected void _unreadChar(int n) throws ConditionThrowable |
---|
134 | { |
---|
135 | notSupported(); |
---|
136 | } |
---|
137 | |
---|
138 | @Override |
---|
139 | protected boolean _charReady() throws ConditionThrowable |
---|
140 | { |
---|
141 | notSupported(); |
---|
142 | // Not reached. |
---|
143 | return false; |
---|
144 | } |
---|
145 | |
---|
146 | @Override |
---|
147 | public void _writeChars(char[] chars, int start, int end) |
---|
148 | throws ConditionThrowable |
---|
149 | { |
---|
150 | _writeString(new String(chars, start, end)); |
---|
151 | } |
---|
152 | |
---|
153 | // Reads an 8-bit byte. |
---|
154 | @Override |
---|
155 | public int _readByte() throws ConditionThrowable |
---|
156 | { |
---|
157 | notSupported(); |
---|
158 | // Not reached. |
---|
159 | return -1; |
---|
160 | } |
---|
161 | |
---|
162 | // Writes an 8-bit byte. |
---|
163 | @Override |
---|
164 | public void _writeByte(int n) throws ConditionThrowable |
---|
165 | { |
---|
166 | notSupported(); |
---|
167 | } |
---|
168 | |
---|
169 | @Override |
---|
170 | public void _finishOutput() throws ConditionThrowable |
---|
171 | { |
---|
172 | target._finishOutput(); |
---|
173 | } |
---|
174 | |
---|
175 | @Override |
---|
176 | public void _clearInput() throws ConditionThrowable |
---|
177 | { |
---|
178 | notSupported(); |
---|
179 | } |
---|
180 | |
---|
181 | @Override |
---|
182 | public LispObject close(LispObject abort) throws ConditionThrowable |
---|
183 | { |
---|
184 | setOpen(false); |
---|
185 | return T; |
---|
186 | } |
---|
187 | |
---|
188 | @Override |
---|
189 | public LispObject listen() throws ConditionThrowable |
---|
190 | { |
---|
191 | notSupported(); |
---|
192 | // Not reached. |
---|
193 | return NIL; |
---|
194 | } |
---|
195 | |
---|
196 | @Override |
---|
197 | public LispObject terpri() throws ConditionThrowable |
---|
198 | { |
---|
199 | return target.terpri(); |
---|
200 | } |
---|
201 | |
---|
202 | @Override |
---|
203 | public LispObject freshLine() throws ConditionThrowable |
---|
204 | { |
---|
205 | return target.freshLine(); |
---|
206 | } |
---|
207 | |
---|
208 | @Override |
---|
209 | public String writeToString() |
---|
210 | { |
---|
211 | return unreadableString("CASE-FROB-STREAM"); |
---|
212 | } |
---|
213 | |
---|
214 | private void notSupported() throws ConditionThrowable |
---|
215 | { |
---|
216 | error(new TypeError("Operation is not supported for streams of type CASE-FROB-STREAM.")); |
---|
217 | } |
---|
218 | |
---|
219 | // ### make-case-frob-stream target => case-frob-stream |
---|
220 | private static final Primitive MAKE_CASE_FROB_STREAM = |
---|
221 | new Primitive("make-case-frob-stream", PACKAGE_SYS, false, "target kind") |
---|
222 | { |
---|
223 | @Override |
---|
224 | public LispObject execute(LispObject first, LispObject second) |
---|
225 | throws ConditionThrowable |
---|
226 | { |
---|
227 | Stream target = checkCharacterOutputStream(first); |
---|
228 | if (second == Keyword.UPCASE) |
---|
229 | return new UpcaseStream(target); |
---|
230 | if (second == Keyword.DOWNCASE) |
---|
231 | return new DowncaseStream(target); |
---|
232 | if (second == Keyword.CAPITALIZE) |
---|
233 | return new CapitalizeStream(target); |
---|
234 | if (second == Keyword.CAPITALIZE_FIRST) |
---|
235 | return new CapitalizeFirstStream(target); |
---|
236 | return error(new TypeError( |
---|
237 | "Kind must be :UPCASE, :DOWNCASE, :CAPITALIZE or :CAPITALIZE-FIRST.")); |
---|
238 | } |
---|
239 | }; |
---|
240 | } |
---|