source: trunk/abcl/src/org/armedbear/lisp/CaseFrobStream.java

Last change on this file was 15707, checked in by Mark Evenson, 11 months ago

Gray Streams now work much better

Implemented Java-side proxy in GrayStream?.java for a GRAY-STREAM
object which forwards various methods of Stream.java into the correct
CLOS code. Signal Lisp-side errors for any unimplemented
interfaces.

gray-streams: implement Stream._writeChars()

gray-streams: getCharPos() --> STREAM-LINE-COLUMN

Mark GrayStreams?.getOffset() as unimplemented.

gray-streams: fix _readChar() to use character value

gray-streams: fix _unreadChar() to return character value

gray-streams: implement _charReady() stub _byteReady()

gray-streams: wire getElementType() --> STREAM-ELEMENT-TYPE

gray-streams: rename from CLOS Proxy to Gray Stream

gray-streams: move the Gray Stream Java proxies to their own package

gray-streams: tweak compilation order for gray-streams-java

gray-streams: restore Lisp.getStandardOutput() check

gray-stream: restore checkCharacterOutputStream() in CaseFrobStream?

gray-streams: fix CaseFrobStream?()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1/*
2 * CaseFrobStream.java
3 *
4 * Copyright (C) 2004 Peter Graves
5 * $Id: CaseFrobStream.java 15707 2023-06-06 06:39:04Z mevenson $
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
34package org.armedbear.lisp;
35
36import static org.armedbear.lisp.Lisp.*;
37
38public abstract class CaseFrobStream extends Stream
39{
40    protected final Stream target;
41
42    protected CaseFrobStream(Stream target)
43
44    {
45        super(Symbol.CASE_FROB_STREAM);
46        this.target = target;
47    }
48
49    @Override
50    public LispObject getElementType()
51    {
52        return target.getElementType();
53    }
54
55    @Override
56    public LispObject typeOf()
57    {
58        return Symbol.CASE_FROB_STREAM;
59    }
60
61    @Override
62    public LispObject classOf()
63    {
64        return BuiltInClass.CASE_FROB_STREAM;
65    }
66
67    @Override
68    public LispObject typep(LispObject type)
69    {
70        if (type == Symbol.CASE_FROB_STREAM)
71            return T;
72        if (type == BuiltInClass.CASE_FROB_STREAM)
73            return T;
74        return super.typep(type);
75    }
76
77    @Override
78    public boolean isInputStream()
79    {
80        return false;
81    }
82
83    @Override
84    public boolean isOutputStream()
85    {
86        return true;
87    }
88
89    @Override
90    public boolean isCharacterInputStream()
91    {
92        return false;
93    }
94
95    @Override
96    public boolean isBinaryInputStream()
97    {
98        return false;
99    }
100
101    @Override
102    public boolean isCharacterOutputStream()
103    {
104        return true;
105    }
106
107    @Override
108    public boolean isBinaryOutputStream()
109    {
110        return false;
111    }
112
113    @Override
114    public int getCharPos()
115    {
116        return target.getCharPos();
117    }
118
119    @Override
120    public void setCharPos(int n)
121    {
122        target.setCharPos(n);
123    }
124
125    // Returns -1 at end of file.
126    @Override
127    protected int _readChar()
128    {
129        notSupported();
130        // Not reached.
131        return -1;
132    }
133
134    @Override
135    protected void _unreadChar(int n)
136    {
137        notSupported();
138    }
139
140    @Override
141    protected boolean _charReady()
142    {
143        notSupported();
144        // Not reached.
145        return false;
146    }
147
148    @Override
149    public void _writeChars(char[] chars, int start, int end)
150
151    {
152        _writeString(new String(chars, start, end));
153    }
154
155    // Reads an 8-bit byte.
156    @Override
157    public int _readByte()
158    {
159        notSupported();
160        // Not reached.
161        return -1;
162    }
163
164    // Writes an 8-bit byte.
165    @Override
166    public void _writeByte(int n)
167    {
168        notSupported();
169    }
170
171    @Override
172    public void _finishOutput()
173    {
174        target._finishOutput();
175    }
176
177    @Override
178    public void _clearInput()
179    {
180        notSupported();
181    }
182
183    @Override
184    public LispObject close(LispObject abort)
185    {
186        setOpen(false);
187        return T;
188    }
189
190    @Override
191    public LispObject listen()
192    {
193        notSupported();
194        // Not reached.
195        return NIL;
196    }
197
198    @Override
199    public LispObject terpri()
200    {
201        return target.terpri();
202    }
203
204    @Override
205    public LispObject freshLine()
206    {
207        return target.freshLine();
208    }
209
210    @Override
211    public String printObject()
212    {
213        return unreadableString("CASE-FROB-STREAM");
214    }
215
216    private void notSupported()
217    {
218        error(new TypeError("Operation is not supported for streams of type CASE-FROB-STREAM."));
219    }
220
221    // ### make-case-frob-stream target => case-frob-stream
222    private static final Primitive MAKE_CASE_FROB_STREAM =
223        new Primitive("make-case-frob-stream", PACKAGE_SYS, false, "target kind")
224    {
225        @Override
226        public LispObject execute(LispObject first, LispObject second)
227
228        {
229            Stream target = checkCharacterOutputStream(first);
230            if (second == Keyword.UPCASE)
231                return new UpcaseStream(target);
232            if (second == Keyword.DOWNCASE)
233                return new DowncaseStream(target);
234            if (second == Keyword.CAPITALIZE)
235                return new CapitalizeStream(target);
236            if (second == Keyword.CAPITALIZE_FIRST)
237                return new CapitalizeFirstStream(target);
238            return error(new TypeError(
239                "Kind must be :UPCASE, :DOWNCASE, :CAPITALIZE or :CAPITALIZE-FIRST."));
240        }
241    };
242}
Note: See TracBrowser for help on using the repository browser.