KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > SynonymStream


1 /*
2  * SynonymStream.java
3  *
4  * Copyright (C) 2004 Peter Graves
5  * $Id: SynonymStream.java,v 1.6 2004/06/23 01:41:51 piso Exp $
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
22 package org.armedbear.lisp;
23
24 public final class SynonymStream extends Stream
25 {
26     private final Symbol symbol;
27
28     private SynonymStream(Symbol symbol)
29     {
30         this.symbol = symbol;
31     }
32
33     public boolean isInputStream() throws ConditionThrowable
34     {
35         return checkStream(symbol.symbolValue()).isInputStream();
36     }
37
38     public boolean isOutputStream() throws ConditionThrowable
39     {
40         return checkStream(symbol.symbolValue()).isOutputStream();
41     }
42
43     public boolean isCharacterInputStream() throws ConditionThrowable
44     {
45         return checkStream(symbol.symbolValue()).isCharacterInputStream();
46     }
47
48     public boolean isBinaryInputStream() throws ConditionThrowable
49     {
50         return checkStream(symbol.symbolValue()).isBinaryInputStream();
51     }
52
53     public boolean isCharacterOutputStream() throws ConditionThrowable
54     {
55         return checkStream(symbol.symbolValue()).isCharacterOutputStream();
56     }
57
58     public boolean isBinaryOutputStream() throws ConditionThrowable
59     {
60         return checkStream(symbol.symbolValue()).isBinaryOutputStream();
61     }
62
63     public LispObject typeOf()
64     {
65         return Symbol.SYNONYM_STREAM;
66     }
67
68     public LispClass classOf()
69     {
70         return BuiltInClass.SYNONYM_STREAM;
71     }
72
73     public LispObject typep(LispObject typeSpecifier) throws ConditionThrowable
74     {
75         if (typeSpecifier == Symbol.SYNONYM_STREAM)
76             return T;
77         if (typeSpecifier == BuiltInClass.SYNONYM_STREAM)
78             return T;
79         return super.typep(typeSpecifier);
80     }
81
82     public LispObject getElementType() throws ConditionThrowable
83     {
84         return checkStream(symbol.symbolValue()).getElementType();
85     }
86
87     public LispObject listen() throws ConditionThrowable
88     {
89         return checkStream(symbol.symbolValue()).listen();
90     }
91
92     public LispObject fileLength() throws ConditionThrowable
93     {
94         return checkStream(symbol.symbolValue()).fileLength();
95     }
96
97     public LispObject fileStringLength(LispObject arg) throws ConditionThrowable
98     {
99         return checkStream(symbol.symbolValue()).fileStringLength(arg);
100     }
101
102     protected int _readChar() throws ConditionThrowable
103     {
104         return checkStream(symbol.symbolValue())._readChar();
105     }
106
107     protected void _unreadChar(int n) throws ConditionThrowable
108     {
109         checkStream(symbol.symbolValue())._unreadChar(n);
110     }
111
112     protected boolean _charReady() throws ConditionThrowable
113     {
114         return checkStream(symbol.symbolValue())._charReady();
115     }
116
117     public void _writeChar(char c) throws ConditionThrowable
118     {
119         checkStream(symbol.symbolValue())._writeChar(c);
120     }
121
122     public void _writeChars(char[] chars, int start, int end)
123         throws ConditionThrowable
124     {
125         checkStream(symbol.symbolValue())._writeChars(chars, start, end);
126     }
127
128     public void _writeString(String JavaDoc s) throws ConditionThrowable
129     {
130         checkStream(symbol.symbolValue())._writeString(s);
131     }
132
133     public void _writeLine(String JavaDoc s) throws ConditionThrowable
134     {
135         checkStream(symbol.symbolValue())._writeLine(s);
136     }
137
138     // Reads an 8-bit byte.
139
public int _readByte() throws ConditionThrowable
140     {
141         return checkStream(symbol.symbolValue())._readByte();
142     }
143
144     // Writes an 8-bit byte.
145
public void _writeByte(int n) throws ConditionThrowable
146     {
147         checkStream(symbol.symbolValue())._writeByte(n);
148     }
149
150     public void _finishOutput() throws ConditionThrowable
151     {
152         checkStream(symbol.symbolValue())._finishOutput();
153     }
154
155     public void _clearInput() throws ConditionThrowable
156     {
157         checkStream(symbol.symbolValue())._clearInput();
158     }
159
160     protected long _getFilePosition() throws ConditionThrowable
161     {
162         return checkStream(symbol.symbolValue())._getFilePosition();
163     }
164
165     protected boolean _setFilePosition(LispObject arg) throws ConditionThrowable
166     {
167         return checkStream(symbol.symbolValue())._setFilePosition(arg);
168     }
169
170     public void _close() throws ConditionThrowable
171     {
172         checkStream(symbol.symbolValue())._close();
173     }
174
175     public String JavaDoc writeToString() throws ConditionThrowable
176     {
177         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("SYNONYM-STREAM ");
178         sb.append(symbol.writeToString());
179         return unreadableString(sb.toString());
180     }
181
182     // ### make-synonym-stream symbol => synonym-stream
183
private static final Primitive MAKE_SYNONYM_STREAM =
184         new Primitive("make-synonym-stream", "symbol")
185     {
186         public LispObject execute(LispObject arg) throws ConditionThrowable
187         {
188             return new SynonymStream(checkSymbol(arg));
189         }
190     };
191
192     // ### synonym-stream-symbol synonym-stream => symbol
193
private static final Primitive1 SYNONYM_STREAM_STREAMS =
194         new Primitive1("synonym-stream-symbol", "synonym-stream")
195     {
196         public LispObject execute(LispObject arg) throws ConditionThrowable
197         {
198             try {
199                 return ((SynonymStream)arg).symbol;
200             }
201             catch (ClassCastException JavaDoc e) {
202                 return signal(new TypeError(arg, Symbol.SYNONYM_STREAM));
203             }
204         }
205     };
206 }
207
Popular Tags