001: /*
002: * CaseFrobStream.java
003: *
004: * Copyright (C) 2004 Peter Graves
005: * $Id: CaseFrobStream.java,v 1.4 2004/06/22 23:07:46 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 abstract class CaseFrobStream extends Stream {
025: protected final Stream target;
026:
027: protected CaseFrobStream(Stream target) throws ConditionThrowable {
028: Debug.assertTrue(target.isCharacterOutputStream());
029: this .target = target;
030: }
031:
032: public LispObject getElementType() throws ConditionThrowable {
033: return target.getElementType();
034: }
035:
036: public LispObject typeOf() {
037: return Symbol.CASE_FROB_STREAM;
038: }
039:
040: public LispClass classOf() {
041: return BuiltInClass.CASE_FROB_STREAM;
042: }
043:
044: public LispObject typep(LispObject type) throws ConditionThrowable {
045: if (type == Symbol.CASE_FROB_STREAM)
046: return T;
047: if (type == BuiltInClass.CASE_FROB_STREAM)
048: return T;
049: return super .typep(type);
050: }
051:
052: public boolean isInputStream() {
053: return false;
054: }
055:
056: public boolean isOutputStream() {
057: return true;
058: }
059:
060: public boolean isCharacterInputStream() throws ConditionThrowable {
061: return false;
062: }
063:
064: public boolean isBinaryInputStream() throws ConditionThrowable {
065: return false;
066: }
067:
068: public boolean isCharacterOutputStream() throws ConditionThrowable {
069: return true;
070: }
071:
072: public boolean isBinaryOutputStream() throws ConditionThrowable {
073: return false;
074: }
075:
076: public int getCharPos() {
077: return target.getCharPos();
078: }
079:
080: public void setCharPos(int n) {
081: target.setCharPos(n);
082: }
083:
084: // Returns -1 at end of file.
085: protected int _readChar() throws ConditionThrowable {
086: notSupported();
087: // Not reached.
088: return -1;
089: }
090:
091: protected void _unreadChar(int n) throws ConditionThrowable {
092: notSupported();
093: }
094:
095: protected boolean _charReady() throws ConditionThrowable {
096: notSupported();
097: // Not reached.
098: return false;
099: }
100:
101: public void _writeChars(char[] chars, int start, int end)
102: throws ConditionThrowable {
103: _writeString(new String(chars, start, end));
104: }
105:
106: // Reads an 8-bit byte.
107: public int _readByte() throws ConditionThrowable {
108: notSupported();
109: // Not reached.
110: return -1;
111: }
112:
113: // Writes an 8-bit byte.
114: public void _writeByte(int n) throws ConditionThrowable {
115: notSupported();
116: }
117:
118: public void _finishOutput() throws ConditionThrowable {
119: target._finishOutput();
120: }
121:
122: public void _clearInput() throws ConditionThrowable {
123: notSupported();
124: }
125:
126: public LispObject close(LispObject abort) throws ConditionThrowable {
127: setOpen(false);
128: return T;
129: }
130:
131: public LispObject listen() throws ConditionThrowable {
132: notSupported();
133: // Not reached.
134: return NIL;
135: }
136:
137: public LispObject terpri() throws ConditionThrowable {
138: return target.terpri();
139: }
140:
141: public LispObject freshLine() throws ConditionThrowable {
142: return target.freshLine();
143: }
144:
145: public String writeToString() {
146: return unreadableString("CASE-FROB-STREAM");
147: }
148:
149: private void notSupported() throws ConditionThrowable {
150: signal(new TypeError(
151: "Operation is not supported for streams of type CASE-FROB-STREAM."));
152: }
153:
154: // ### make-case-frob-stream target => case-frob-stream
155: private static final Primitive2 MAKE_CASE_FROB_STREAM = new Primitive2(
156: "make-case-frob-stream", PACKAGE_SYS, false, "target kind") {
157: public LispObject execute(LispObject first, LispObject second)
158: throws ConditionThrowable {
159: Stream target = checkCharacterOutputStream(first);
160: if (second == Keyword.UPCASE)
161: return new UpcaseStream(target);
162: if (second == Keyword.DOWNCASE)
163: return new DowncaseStream(target);
164: if (second == Keyword.CAPITALIZE)
165: return new CapitalizeStream(target);
166: if (second == Keyword.CAPITALIZE_FIRST)
167: return new CapitalizeFirstStream(target);
168: return signal(new TypeError(
169: "Kind must be :UPCASE, :DOWNCASE, :CAPITALIZE or :CAPITALIZE-FIRST."));
170: }
171: };
172: }
|