KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CaseFrobStream.java
3  *
4  * Copyright (C) 2004 Peter Graves
5  * $Id: CaseFrobStream.java,v 1.4 2004/06/22 23:07:46 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 abstract class CaseFrobStream extends Stream
25 {
26     protected final Stream target;
27
28     protected CaseFrobStream(Stream target)
29         throws ConditionThrowable
30     {
31         Debug.assertTrue(target.isCharacterOutputStream());
32         this.target = target;
33     }
34
35     public LispObject getElementType() throws ConditionThrowable
36     {
37         return target.getElementType();
38     }
39
40     public LispObject typeOf()
41     {
42         return Symbol.CASE_FROB_STREAM;
43     }
44
45     public LispClass classOf()
46     {
47         return BuiltInClass.CASE_FROB_STREAM;
48     }
49
50     public LispObject typep(LispObject type) throws ConditionThrowable
51     {
52         if (type == Symbol.CASE_FROB_STREAM)
53             return T;
54         if (type == BuiltInClass.CASE_FROB_STREAM)
55             return T;
56         return super.typep(type);
57     }
58
59     public boolean isInputStream()
60     {
61         return false;
62     }
63
64     public boolean isOutputStream()
65     {
66         return true;
67     }
68
69     public boolean isCharacterInputStream() throws ConditionThrowable
70     {
71         return false;
72     }
73
74     public boolean isBinaryInputStream() throws ConditionThrowable
75     {
76         return false;
77     }
78
79     public boolean isCharacterOutputStream() throws ConditionThrowable
80     {
81         return true;
82     }
83
84     public boolean isBinaryOutputStream() throws ConditionThrowable
85     {
86         return false;
87     }
88
89     public int getCharPos()
90     {
91         return target.getCharPos();
92     }
93
94     public void setCharPos(int n)
95     {
96         target.setCharPos(n);
97     }
98
99     // Returns -1 at end of file.
100
protected int _readChar() throws ConditionThrowable
101     {
102         notSupported();
103         // Not reached.
104
return -1;
105     }
106
107     protected void _unreadChar(int n) throws ConditionThrowable
108     {
109         notSupported();
110     }
111
112     protected boolean _charReady() throws ConditionThrowable
113     {
114         notSupported();
115         // Not reached.
116
return false;
117     }
118
119     public void _writeChars(char[] chars, int start, int end)
120         throws ConditionThrowable
121     {
122         _writeString(new String JavaDoc(chars, start, end));
123     }
124
125     // Reads an 8-bit byte.
126
public int _readByte() throws ConditionThrowable
127     {
128         notSupported();
129         // Not reached.
130
return -1;
131     }
132
133     // Writes an 8-bit byte.
134
public void _writeByte(int n) throws ConditionThrowable
135     {
136         notSupported();
137     }
138
139     public void _finishOutput() throws ConditionThrowable
140     {
141         target._finishOutput();
142     }
143
144     public void _clearInput() throws ConditionThrowable
145     {
146         notSupported();
147     }
148
149     public LispObject close(LispObject abort) throws ConditionThrowable
150     {
151         setOpen(false);
152         return T;
153     }
154
155     public LispObject listen() throws ConditionThrowable
156     {
157         notSupported();
158         // Not reached.
159
return NIL;
160     }
161
162     public LispObject terpri() throws ConditionThrowable
163     {
164         return target.terpri();
165     }
166
167     public LispObject freshLine() throws ConditionThrowable
168     {
169         return target.freshLine();
170     }
171
172     public String JavaDoc writeToString()
173     {
174         return unreadableString("CASE-FROB-STREAM");
175     }
176
177     private void notSupported() throws ConditionThrowable
178     {
179         signal(new TypeError("Operation is not supported for streams of type CASE-FROB-STREAM."));
180     }
181
182     // ### make-case-frob-stream target => case-frob-stream
183
private static final Primitive2 MAKE_CASE_FROB_STREAM =
184         new Primitive2("make-case-frob-stream", PACKAGE_SYS, false, "target kind")
185     {
186         public LispObject execute(LispObject first, LispObject second)
187             throws ConditionThrowable
188         {
189             Stream target = checkCharacterOutputStream(first);
190             if (second == Keyword.UPCASE)
191                 return new UpcaseStream(target);
192             if (second == Keyword.DOWNCASE)
193                 return new DowncaseStream(target);
194             if (second == Keyword.CAPITALIZE)
195                 return new CapitalizeStream(target);
196             if (second == Keyword.CAPITALIZE_FIRST)
197                 return new CapitalizeFirstStream(target);
198             return signal(new TypeError(
199                 "Kind must be :UPCASE, :DOWNCASE, :CAPITALIZE or :CAPITALIZE-FIRST."));
200         }
201     };
202 }
203
Popular Tags