Changeset 11420


Ignore:
Timestamp:
12/05/08 23:28:55 (12 years ago)
Author:
ehuelsmann
Message:

Cleanup: with the right initialization, we can reuse most of the code in the superclass.

Location:
branches/open-external-format/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/open-external-format/src/org/armedbear/lisp/StringInputStream.java

    r11418 r11420  
    3434package org.armedbear.lisp;
    3535
     36import java.io.IOException;
     37import java.io.StringReader;
     38
    3639public final class StringInputStream extends Stream
    3740{
     
    4043    final int end;
    4144
     45    private final StringReader stringReader;
     46   
    4247    public StringInputStream(String s)
    4348    {
     
    5358    {
    5459        elementType = Symbol.CHARACTER;
    55         isInputStream = true;
    56         isOutputStream = false;
    57         isCharacterStream = true;
    58         isBinaryStream = false;
     60        setExternalFormat(keywordDefault);
    5961        this.s = s;
    6062        this.start = start;
    6163        this.end = end;
    62         offset = start;
     64       
     65        stringReader = new StringReader(s.substring(start, end));
     66        initAsCharacterInputStream(stringReader);
    6367    }
    6468
     
    8791            return T;
    8892        return super.typep(type);
    89     }
    90 
    91     @Override
    92     public LispObject close(LispObject abort) throws ConditionThrowable
    93     {
    94         setOpen(false);
    95         return T;
    96     }
    97 
    98     @Override
    99     public LispObject listen()
    100     {
    101         return offset < end ? T : NIL;
    102     }
    103 
    104     @Override
    105     protected int _readChar()
    106     {
    107         if (offset >= end)
    108             return -1;
    109         int n = s.charAt(offset);
    110         ++offset;
    111             if (n == '\n')
    112             ++lineNumber;
    113         return n;
    114     }
    115 
    116     @Override
    117     protected void _unreadChar(int n)
    118     {
    119         if (offset > start) {
    120             --offset;
    121             if (n == '\n')
    122                 --lineNumber;
    123         }
    12493    }
    12594
  • branches/open-external-format/src/org/armedbear/lisp/StringOutputStream.java

    r11418 r11420  
    4848    {
    4949        this.elementType = elementType;
    50         isInputStream = false;
    51         isOutputStream = true;
    52         isCharacterStream = true;
    53         isBinaryStream = false;
    54         setWriter(stringWriter = new StringWriter());
     50        initAsCharacterOutputStream(stringWriter = new StringWriter());
    5551    }
    5652
     
    7975            return T;
    8076        return super.typep(type);
    81     }
    82 
    83     @Override
    84     public void _writeChar(char c) throws ConditionThrowable
    85     {
    86         if (elementType == NIL)
    87             writeError();
    88         super._writeChar(c);
    89     }
    90 
    91     @Override
    92     public void _writeChars(char[] chars, int start, int end)
    93         throws ConditionThrowable
    94     {
    95         if (elementType == NIL)
    96             writeError();
    97         super._writeChars(chars, start, end);
    98     }
    99 
    100     @Override
    101     public void _writeString(String s) throws ConditionThrowable
    102     {
    103         if (elementType == NIL)
    104             writeError();
    105         super._writeString(s);
    106     }
    107 
    108     @Override
    109     public void _writeLine(String s) throws ConditionThrowable
    110     {
    111         if (elementType == NIL)
    112             writeError();
    113         super._writeLine(s);
    114     }
    115 
    116     private void writeError() throws ConditionThrowable
    117     {
    118         error(new TypeError("Attempt to write to a string output stream of element type NIL."));
    11977    }
    12078
Note: See TracChangeset for help on using the changeset viewer.