Changeset 11415


Ignore:
Timestamp:
12/04/08 23:02:20 (13 years ago)
Author:
ehuelsmann
Message:

Support EXTERNAL-FORMAT for socket streams.

Found by: Hideo at Yokohama

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

Legend:

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

    r11414 r11415  
    114114  private OutputStream out;
    115115
    116   // end of line character sequence.
    117   private char[] eolseq;
    118  
    119   private void setEolSeq() {
    120     if (eolStyle == EolStyle.CRLF) {
    121       eolseq = new char[] { '\r', '\n' };
    122     } else if (eolStyle == EolStyle.CR) {
    123       eolseq = new char[] { '\r' };
    124     } else {
    125       eolseq = new char[] { '\n' };
    126     }
    127   }
    128 
    129116  protected Stream()
    130117  {
    131     setEolSeq();
    132118  }
    133119
    134120  public Stream(InputStream inputStream, LispObject elementType)
    135121    {
    136       this(inputStream, elementType, null);
     122      this(inputStream, elementType, keywordDefault);
    137123    }
    138124
    139125
    140126  // Input stream constructors.
    141     public Stream(InputStream inputStream, LispObject elementType, String encoding)
     127    public Stream(InputStream inputStream, LispObject elementType, LispObject format)
    142128  {
    143129    this.elementType = elementType;
     130    setExternalFormat(format);
    144131    if (elementType == Symbol.CHARACTER || elementType == Symbol.BASE_CHAR)
    145132      {
     
    168155  initAsBinaryInputStream(in);
    169156      }
    170     setEolSeq();
    171157  }
    172158
     
    179165  public Stream(OutputStream outputStream, LispObject elementType)
    180166    {
    181       this(outputStream, elementType, null);
     167      this(outputStream, elementType, keywordDefault);
    182168    }
    183169   
    184170  // Output stream constructors.
    185   public Stream(OutputStream outputStream, LispObject elementType, String encoding)
     171  public Stream(OutputStream outputStream, LispObject elementType, LispObject format)
    186172  {
    187173    this.elementType = elementType;
     174    setExternalFormat(format);
    188175    if (elementType == Symbol.CHARACTER || elementType == Symbol.BASE_CHAR)
    189176      {
     
    207194  initAsBinaryOutputStream(out);
    208195      }
    209     setEolSeq();
    210196  }
    211197
     
    296282      eolChar = (eolStyle == EolStyle.CR) ? '\r' : '\n';
    297283      externalFormat = format;
    298       setEolSeq();
    299284      return;
    300285    }
     
    18911876        if (c == '\n') {
    18921877    writer.write(eolseq);
    1893           writer.flush();
     1878            writer.flush();
    18941879          charPos = 0;
    18951880        } else {
     
    19291914         
    19301915        } else
    1931           writer.write(chars, start, end - start);
     1916        writer.write(chars, start, end - start);
    19321917       
    19331918        int index = -1;
     
    19481933          {
    19491934            charPos = end - (index + 1);
    1950             writer.flush();
     1935              writer.flush();
    19511936      }
    19521937    }
  • branches/open-external-format/src/org/armedbear/lisp/socket.lisp

    r11408 r11415  
    3232(in-package "SYSTEM")
    3333
    34 (defun get-socket-stream (socket &key (element-type 'character))
    35   ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8); the default is CHARACTER."
     34(defun get-socket-stream (socket &key (element-type 'character) (external-format :default))
     35  ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8); the default is CHARACTER.
     36EXTERNAL-FORMAT must be of the same format as specified for OPEN."
    3637  (cond ((eq element-type 'character))
    3738        ((equal element-type '(unsigned-byte 8)))
     
    4041                :format-control
    4142                ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8).")))
    42   (%socket-stream socket element-type))
     43  (%socket-stream socket element-type external-format))
    4344
    4445(defun make-socket (host port)
  • branches/open-external-format/src/org/armedbear/lisp/socket_stream.java

    r11408 r11415  
    4141    private socket_stream()
    4242    {
    43         super("%socket-stream", PACKAGE_SYS, false, "socket element-type");
     43        super("%socket-stream", PACKAGE_SYS, false, "socket element-type external-format");
    4444    }
    4545
    46     public LispObject execute(LispObject first, LispObject second)
     46    public LispObject execute(LispObject first, LispObject second, LispObject third)
    4747        throws ConditionThrowable
    4848    {
     
    5151        try {
    5252             Stream in =
    53                  new Stream(socket.getInputStream(), elementType);
     53                 new Stream(socket.getInputStream(), elementType, third);
    5454             Stream out =
    55                  new Stream(socket.getOutputStream(), elementType);
     55                 new Stream(socket.getOutputStream(), elementType, third);
    5656             return new SocketStream(socket, in, out);
    5757        }
Note: See TracChangeset for help on using the changeset viewer.