1 | /* |
---|
2 | * SynonymStream.java |
---|
3 | * |
---|
4 | * Copyright (C) 2004 Peter Graves |
---|
5 | * $Id: SynonymStream.java 12254 2009-11-06 20:07:54Z 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 final class SynonymStream extends Stream |
---|
37 | { |
---|
38 | private final Symbol symbol; |
---|
39 | |
---|
40 | private SynonymStream(Symbol symbol) |
---|
41 | { |
---|
42 | this.symbol = symbol; |
---|
43 | } |
---|
44 | |
---|
45 | @Override |
---|
46 | public boolean isInputStream() |
---|
47 | { |
---|
48 | return checkStream(symbol.symbolValue()).isInputStream(); |
---|
49 | } |
---|
50 | |
---|
51 | @Override |
---|
52 | public boolean isOutputStream() |
---|
53 | { |
---|
54 | return checkStream(symbol.symbolValue()).isOutputStream(); |
---|
55 | } |
---|
56 | |
---|
57 | @Override |
---|
58 | public boolean isCharacterInputStream() |
---|
59 | { |
---|
60 | return checkStream(symbol.symbolValue()).isCharacterInputStream(); |
---|
61 | } |
---|
62 | |
---|
63 | @Override |
---|
64 | public boolean isBinaryInputStream() |
---|
65 | { |
---|
66 | return checkStream(symbol.symbolValue()).isBinaryInputStream(); |
---|
67 | } |
---|
68 | |
---|
69 | @Override |
---|
70 | public boolean isCharacterOutputStream() |
---|
71 | { |
---|
72 | return checkStream(symbol.symbolValue()).isCharacterOutputStream(); |
---|
73 | } |
---|
74 | |
---|
75 | @Override |
---|
76 | public boolean isBinaryOutputStream() |
---|
77 | { |
---|
78 | return checkStream(symbol.symbolValue()).isBinaryOutputStream(); |
---|
79 | } |
---|
80 | |
---|
81 | @Override |
---|
82 | public LispObject typeOf() |
---|
83 | { |
---|
84 | return Symbol.SYNONYM_STREAM; |
---|
85 | } |
---|
86 | |
---|
87 | @Override |
---|
88 | public LispObject classOf() |
---|
89 | { |
---|
90 | return BuiltInClass.SYNONYM_STREAM; |
---|
91 | } |
---|
92 | |
---|
93 | @Override |
---|
94 | public LispObject typep(LispObject typeSpecifier) |
---|
95 | { |
---|
96 | if (typeSpecifier == Symbol.SYNONYM_STREAM) |
---|
97 | return T; |
---|
98 | if (typeSpecifier == BuiltInClass.SYNONYM_STREAM) |
---|
99 | return T; |
---|
100 | return super.typep(typeSpecifier); |
---|
101 | } |
---|
102 | |
---|
103 | @Override |
---|
104 | public LispObject getElementType() |
---|
105 | { |
---|
106 | return checkStream(symbol.symbolValue()).getElementType(); |
---|
107 | } |
---|
108 | |
---|
109 | @Override |
---|
110 | public LispObject listen() |
---|
111 | { |
---|
112 | return checkStream(symbol.symbolValue()).listen(); |
---|
113 | } |
---|
114 | |
---|
115 | @Override |
---|
116 | public LispObject fileLength() |
---|
117 | { |
---|
118 | return checkStream(symbol.symbolValue()).fileLength(); |
---|
119 | } |
---|
120 | |
---|
121 | @Override |
---|
122 | public LispObject fileStringLength(LispObject arg) |
---|
123 | { |
---|
124 | return checkStream(symbol.symbolValue()).fileStringLength(arg); |
---|
125 | } |
---|
126 | |
---|
127 | @Override |
---|
128 | protected int _readChar() throws java.io.IOException |
---|
129 | { |
---|
130 | return checkStream(symbol.symbolValue())._readChar(); |
---|
131 | } |
---|
132 | |
---|
133 | @Override |
---|
134 | protected void _unreadChar(int n) throws java.io.IOException |
---|
135 | { |
---|
136 | checkStream(symbol.symbolValue())._unreadChar(n); |
---|
137 | } |
---|
138 | |
---|
139 | @Override |
---|
140 | protected boolean _charReady() throws java.io.IOException |
---|
141 | { |
---|
142 | return checkStream(symbol.symbolValue())._charReady(); |
---|
143 | } |
---|
144 | |
---|
145 | @Override |
---|
146 | public void _writeChar(char c) |
---|
147 | { |
---|
148 | checkStream(symbol.symbolValue())._writeChar(c); |
---|
149 | } |
---|
150 | |
---|
151 | @Override |
---|
152 | public void _writeChars(char[] chars, int start, int end) |
---|
153 | |
---|
154 | { |
---|
155 | checkStream(symbol.symbolValue())._writeChars(chars, start, end); |
---|
156 | } |
---|
157 | |
---|
158 | @Override |
---|
159 | public void _writeString(String s) |
---|
160 | { |
---|
161 | checkStream(symbol.symbolValue())._writeString(s); |
---|
162 | } |
---|
163 | |
---|
164 | @Override |
---|
165 | public void _writeLine(String s) |
---|
166 | { |
---|
167 | checkStream(symbol.symbolValue())._writeLine(s); |
---|
168 | } |
---|
169 | |
---|
170 | // Reads an 8-bit byte. |
---|
171 | @Override |
---|
172 | public int _readByte() |
---|
173 | { |
---|
174 | return checkStream(symbol.symbolValue())._readByte(); |
---|
175 | } |
---|
176 | |
---|
177 | // Writes an 8-bit byte. |
---|
178 | @Override |
---|
179 | public void _writeByte(int n) |
---|
180 | { |
---|
181 | checkStream(symbol.symbolValue())._writeByte(n); |
---|
182 | } |
---|
183 | |
---|
184 | @Override |
---|
185 | public void _finishOutput() |
---|
186 | { |
---|
187 | checkStream(symbol.symbolValue())._finishOutput(); |
---|
188 | } |
---|
189 | |
---|
190 | @Override |
---|
191 | public void _clearInput() |
---|
192 | { |
---|
193 | checkStream(symbol.symbolValue())._clearInput(); |
---|
194 | } |
---|
195 | |
---|
196 | @Override |
---|
197 | protected long _getFilePosition() |
---|
198 | { |
---|
199 | return checkStream(symbol.symbolValue())._getFilePosition(); |
---|
200 | } |
---|
201 | |
---|
202 | @Override |
---|
203 | protected boolean _setFilePosition(LispObject arg) |
---|
204 | { |
---|
205 | return checkStream(symbol.symbolValue())._setFilePosition(arg); |
---|
206 | } |
---|
207 | |
---|
208 | @Override |
---|
209 | public void _close() |
---|
210 | { |
---|
211 | checkStream(symbol.symbolValue())._close(); |
---|
212 | } |
---|
213 | |
---|
214 | @Override |
---|
215 | public String writeToString() |
---|
216 | { |
---|
217 | StringBuffer sb = new StringBuffer("SYNONYM-STREAM "); |
---|
218 | sb.append(symbol.writeToString()); |
---|
219 | return unreadableString(sb.toString()); |
---|
220 | } |
---|
221 | |
---|
222 | // ### make-synonym-stream symbol => synonym-stream |
---|
223 | private static final Primitive MAKE_SYNONYM_STREAM = |
---|
224 | new Primitive("make-synonym-stream", "symbol") |
---|
225 | { |
---|
226 | @Override |
---|
227 | public LispObject execute(LispObject arg) |
---|
228 | { |
---|
229 | return new SynonymStream(checkSymbol(arg)); |
---|
230 | } |
---|
231 | }; |
---|
232 | |
---|
233 | // ### synonym-stream-symbol synonym-stream => symbol |
---|
234 | private static final Primitive SYNONYM_STREAM_STREAMS = |
---|
235 | new Primitive("synonym-stream-symbol", "synonym-stream") |
---|
236 | { |
---|
237 | @Override |
---|
238 | public LispObject execute(LispObject arg) |
---|
239 | { |
---|
240 | if (arg instanceof SynonymStream) |
---|
241 | return ((SynonymStream)arg).symbol; |
---|
242 | return error(new TypeError(arg, Symbol.SYNONYM_STREAM)); |
---|
243 | } |
---|
244 | }; |
---|
245 | } |
---|