001: /*
002: * SynonymStream.java
003: *
004: * Copyright (C) 2004 Peter Graves
005: * $Id: SynonymStream.java,v 1.6 2004/06/23 01:41:51 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.lisp;
023:
024: public final class SynonymStream extends Stream {
025: private final Symbol symbol;
026:
027: private SynonymStream(Symbol symbol) {
028: this .symbol = symbol;
029: }
030:
031: public boolean isInputStream() throws ConditionThrowable {
032: return checkStream(symbol.symbolValue()).isInputStream();
033: }
034:
035: public boolean isOutputStream() throws ConditionThrowable {
036: return checkStream(symbol.symbolValue()).isOutputStream();
037: }
038:
039: public boolean isCharacterInputStream() throws ConditionThrowable {
040: return checkStream(symbol.symbolValue())
041: .isCharacterInputStream();
042: }
043:
044: public boolean isBinaryInputStream() throws ConditionThrowable {
045: return checkStream(symbol.symbolValue()).isBinaryInputStream();
046: }
047:
048: public boolean isCharacterOutputStream() throws ConditionThrowable {
049: return checkStream(symbol.symbolValue())
050: .isCharacterOutputStream();
051: }
052:
053: public boolean isBinaryOutputStream() throws ConditionThrowable {
054: return checkStream(symbol.symbolValue()).isBinaryOutputStream();
055: }
056:
057: public LispObject typeOf() {
058: return Symbol.SYNONYM_STREAM;
059: }
060:
061: public LispClass classOf() {
062: return BuiltInClass.SYNONYM_STREAM;
063: }
064:
065: public LispObject typep(LispObject typeSpecifier)
066: throws ConditionThrowable {
067: if (typeSpecifier == Symbol.SYNONYM_STREAM)
068: return T;
069: if (typeSpecifier == BuiltInClass.SYNONYM_STREAM)
070: return T;
071: return super .typep(typeSpecifier);
072: }
073:
074: public LispObject getElementType() throws ConditionThrowable {
075: return checkStream(symbol.symbolValue()).getElementType();
076: }
077:
078: public LispObject listen() throws ConditionThrowable {
079: return checkStream(symbol.symbolValue()).listen();
080: }
081:
082: public LispObject fileLength() throws ConditionThrowable {
083: return checkStream(symbol.symbolValue()).fileLength();
084: }
085:
086: public LispObject fileStringLength(LispObject arg)
087: throws ConditionThrowable {
088: return checkStream(symbol.symbolValue()).fileStringLength(arg);
089: }
090:
091: protected int _readChar() throws ConditionThrowable {
092: return checkStream(symbol.symbolValue())._readChar();
093: }
094:
095: protected void _unreadChar(int n) throws ConditionThrowable {
096: checkStream(symbol.symbolValue())._unreadChar(n);
097: }
098:
099: protected boolean _charReady() throws ConditionThrowable {
100: return checkStream(symbol.symbolValue())._charReady();
101: }
102:
103: public void _writeChar(char c) throws ConditionThrowable {
104: checkStream(symbol.symbolValue())._writeChar(c);
105: }
106:
107: public void _writeChars(char[] chars, int start, int end)
108: throws ConditionThrowable {
109: checkStream(symbol.symbolValue())
110: ._writeChars(chars, start, end);
111: }
112:
113: public void _writeString(String s) throws ConditionThrowable {
114: checkStream(symbol.symbolValue())._writeString(s);
115: }
116:
117: public void _writeLine(String s) throws ConditionThrowable {
118: checkStream(symbol.symbolValue())._writeLine(s);
119: }
120:
121: // Reads an 8-bit byte.
122: public int _readByte() throws ConditionThrowable {
123: return checkStream(symbol.symbolValue())._readByte();
124: }
125:
126: // Writes an 8-bit byte.
127: public void _writeByte(int n) throws ConditionThrowable {
128: checkStream(symbol.symbolValue())._writeByte(n);
129: }
130:
131: public void _finishOutput() throws ConditionThrowable {
132: checkStream(symbol.symbolValue())._finishOutput();
133: }
134:
135: public void _clearInput() throws ConditionThrowable {
136: checkStream(symbol.symbolValue())._clearInput();
137: }
138:
139: protected long _getFilePosition() throws ConditionThrowable {
140: return checkStream(symbol.symbolValue())._getFilePosition();
141: }
142:
143: protected boolean _setFilePosition(LispObject arg)
144: throws ConditionThrowable {
145: return checkStream(symbol.symbolValue())._setFilePosition(arg);
146: }
147:
148: public void _close() throws ConditionThrowable {
149: checkStream(symbol.symbolValue())._close();
150: }
151:
152: public String writeToString() throws ConditionThrowable {
153: StringBuffer sb = new StringBuffer("SYNONYM-STREAM ");
154: sb.append(symbol.writeToString());
155: return unreadableString(sb.toString());
156: }
157:
158: // ### make-synonym-stream symbol => synonym-stream
159: private static final Primitive MAKE_SYNONYM_STREAM = new Primitive(
160: "make-synonym-stream", "symbol") {
161: public LispObject execute(LispObject arg)
162: throws ConditionThrowable {
163: return new SynonymStream(checkSymbol(arg));
164: }
165: };
166:
167: // ### synonym-stream-symbol synonym-stream => symbol
168: private static final Primitive1 SYNONYM_STREAM_STREAMS = new Primitive1(
169: "synonym-stream-symbol", "synonym-stream") {
170: public LispObject execute(LispObject arg)
171: throws ConditionThrowable {
172: try {
173: return ((SynonymStream) arg).symbol;
174: } catch (ClassCastException e) {
175: return signal(new TypeError(arg, Symbol.SYNONYM_STREAM));
176: }
177: }
178: };
179: }
|