[armedbear-cvs] r11420 - branches/open-external-format/src/org/armedbear/lisp
Erik Huelsmann
ehuelsmann at common-lisp.net
Fri Dec 5 23:28:58 UTC 2008
Author: ehuelsmann
Date: Fri Dec 5 23:28:55 2008
New Revision: 11420
Log:
Cleanup: with the right initialization, we can reuse most of the code in the superclass.
Modified:
branches/open-external-format/src/org/armedbear/lisp/StringInputStream.java
branches/open-external-format/src/org/armedbear/lisp/StringOutputStream.java
Modified: branches/open-external-format/src/org/armedbear/lisp/StringInputStream.java
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/StringInputStream.java (original)
+++ branches/open-external-format/src/org/armedbear/lisp/StringInputStream.java Fri Dec 5 23:28:55 2008
@@ -33,12 +33,17 @@
package org.armedbear.lisp;
+import java.io.IOException;
+import java.io.StringReader;
+
public final class StringInputStream extends Stream
{
final String s;
final int start;
final int end;
+ private final StringReader stringReader;
+
public StringInputStream(String s)
{
this(s, 0, s.length());
@@ -52,14 +57,13 @@
public StringInputStream(String s, int start, int end)
{
elementType = Symbol.CHARACTER;
- isInputStream = true;
- isOutputStream = false;
- isCharacterStream = true;
- isBinaryStream = false;
+ setExternalFormat(keywordDefault);
this.s = s;
this.start = start;
this.end = end;
- offset = start;
+
+ stringReader = new StringReader(s.substring(start, end));
+ initAsCharacterInputStream(stringReader);
}
@Override
@@ -89,41 +93,6 @@
}
@Override
- public LispObject close(LispObject abort) throws ConditionThrowable
- {
- setOpen(false);
- return T;
- }
-
- @Override
- public LispObject listen()
- {
- return offset < end ? T : NIL;
- }
-
- @Override
- protected int _readChar()
- {
- if (offset >= end)
- return -1;
- int n = s.charAt(offset);
- ++offset;
- if (n == '\n')
- ++lineNumber;
- return n;
- }
-
- @Override
- protected void _unreadChar(int n)
- {
- if (offset > start) {
- --offset;
- if (n == '\n')
- --lineNumber;
- }
- }
-
- @Override
protected boolean _charReady()
{
return true;
Modified: branches/open-external-format/src/org/armedbear/lisp/StringOutputStream.java
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/StringOutputStream.java (original)
+++ branches/open-external-format/src/org/armedbear/lisp/StringOutputStream.java Fri Dec 5 23:28:55 2008
@@ -47,11 +47,7 @@
private StringOutputStream(LispObject elementType)
{
this.elementType = elementType;
- isInputStream = false;
- isOutputStream = true;
- isCharacterStream = true;
- isBinaryStream = false;
- setWriter(stringWriter = new StringWriter());
+ initAsCharacterOutputStream(stringWriter = new StringWriter());
}
@Override
@@ -81,44 +77,6 @@
}
@Override
- public void _writeChar(char c) throws ConditionThrowable
- {
- if (elementType == NIL)
- writeError();
- super._writeChar(c);
- }
-
- @Override
- public void _writeChars(char[] chars, int start, int end)
- throws ConditionThrowable
- {
- if (elementType == NIL)
- writeError();
- super._writeChars(chars, start, end);
- }
-
- @Override
- public void _writeString(String s) throws ConditionThrowable
- {
- if (elementType == NIL)
- writeError();
- super._writeString(s);
- }
-
- @Override
- public void _writeLine(String s) throws ConditionThrowable
- {
- if (elementType == NIL)
- writeError();
- super._writeLine(s);
- }
-
- private void writeError() throws ConditionThrowable
- {
- error(new TypeError("Attempt to write to a string output stream of element type NIL."));
- }
-
- @Override
protected long _getFilePosition() throws ConditionThrowable
{
if (elementType == NIL)
More information about the armedbear-cvs
mailing list