[armedbear-cvs] r11415 - branches/open-external-format/src/org/armedbear/lisp
Erik Huelsmann
ehuelsmann at common-lisp.net
Thu Dec 4 23:02:21 UTC 2008
Author: ehuelsmann
Date: Thu Dec 4 23:02:20 2008
New Revision: 11415
Log:
Support EXTERNAL-FORMAT for socket streams.
Found by: Hideo at Yokohama
Modified:
branches/open-external-format/src/org/armedbear/lisp/Stream.java
branches/open-external-format/src/org/armedbear/lisp/socket.lisp
branches/open-external-format/src/org/armedbear/lisp/socket_stream.java
Modified: branches/open-external-format/src/org/armedbear/lisp/Stream.java
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/Stream.java (original)
+++ branches/open-external-format/src/org/armedbear/lisp/Stream.java Thu Dec 4 23:02:20 2008
@@ -113,34 +113,21 @@
// Binary output.
private OutputStream out;
- // end of line character sequence.
- private char[] eolseq;
-
- private void setEolSeq() {
- if (eolStyle == EolStyle.CRLF) {
- eolseq = new char[] { '\r', '\n' };
- } else if (eolStyle == EolStyle.CR) {
- eolseq = new char[] { '\r' };
- } else {
- eolseq = new char[] { '\n' };
- }
- }
-
protected Stream()
{
- setEolSeq();
}
public Stream(InputStream inputStream, LispObject elementType)
{
- this(inputStream, elementType, null);
+ this(inputStream, elementType, keywordDefault);
}
// Input stream constructors.
- public Stream(InputStream inputStream, LispObject elementType, String encoding)
+ public Stream(InputStream inputStream, LispObject elementType, LispObject format)
{
this.elementType = elementType;
+ setExternalFormat(format);
if (elementType == Symbol.CHARACTER || elementType == Symbol.BASE_CHAR)
{
InputStreamReader inputStreamReader;
@@ -167,7 +154,6 @@
InputStream in = new BufferedInputStream(inputStream);
initAsBinaryInputStream(in);
}
- setEolSeq();
}
public Stream(InputStream inputStream, LispObject elementType, boolean interactive)
@@ -178,13 +164,14 @@
public Stream(OutputStream outputStream, LispObject elementType)
{
- this(outputStream, elementType, null);
+ this(outputStream, elementType, keywordDefault);
}
// Output stream constructors.
- public Stream(OutputStream outputStream, LispObject elementType, String encoding)
+ public Stream(OutputStream outputStream, LispObject elementType, LispObject format)
{
this.elementType = elementType;
+ setExternalFormat(format);
if (elementType == Symbol.CHARACTER || elementType == Symbol.BASE_CHAR)
{
Writer writer;
@@ -206,7 +193,6 @@
OutputStream out = new BufferedOutputStream(outputStream);
initAsBinaryOutputStream(out);
}
- setEolSeq();
}
public Stream(OutputStream outputStream, LispObject elementType,
@@ -295,7 +281,6 @@
eolStyle = platformEolStyle;
eolChar = (eolStyle == EolStyle.CR) ? '\r' : '\n';
externalFormat = format;
- setEolSeq();
return;
}
@@ -1890,7 +1875,7 @@
{
if (c == '\n') {
writer.write(eolseq);
- writer.flush();
+ writer.flush();
charPos = 0;
} else {
writer.write(c);
@@ -1928,7 +1913,7 @@
_writeChar(chars[i]);
} else
- writer.write(chars, start, end - start);
+ writer.write(chars, start, end - start);
int index = -1;
for (int i = end; i-- > start;)
@@ -1947,7 +1932,7 @@
else
{
charPos = end - (index + 1);
- writer.flush();
+ writer.flush();
}
}
catch (NullPointerException e)
Modified: branches/open-external-format/src/org/armedbear/lisp/socket.lisp
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/socket.lisp (original)
+++ branches/open-external-format/src/org/armedbear/lisp/socket.lisp Thu Dec 4 23:02:20 2008
@@ -31,15 +31,16 @@
(in-package "SYSTEM")
-(defun get-socket-stream (socket &key (element-type 'character))
- ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8); the default is CHARACTER."
+(defun get-socket-stream (socket &key (element-type 'character) (external-format :default))
+ ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8); the default is CHARACTER.
+EXTERNAL-FORMAT must be of the same format as specified for OPEN."
(cond ((eq element-type 'character))
((equal element-type '(unsigned-byte 8)))
(t
(error 'simple-type-error
:format-control
":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8).")))
- (%socket-stream socket element-type))
+ (%socket-stream socket element-type external-format))
(defun make-socket (host port)
(%make-socket host port))
Modified: branches/open-external-format/src/org/armedbear/lisp/socket_stream.java
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/socket_stream.java (original)
+++ branches/open-external-format/src/org/armedbear/lisp/socket_stream.java Thu Dec 4 23:02:20 2008
@@ -40,19 +40,19 @@
{
private socket_stream()
{
- super("%socket-stream", PACKAGE_SYS, false, "socket element-type");
+ super("%socket-stream", PACKAGE_SYS, false, "socket element-type external-format");
}
- public LispObject execute(LispObject first, LispObject second)
+ public LispObject execute(LispObject first, LispObject second, LispObject third)
throws ConditionThrowable
{
Socket socket = (Socket) ((JavaObject)first).getObject();
LispObject elementType = second; // Checked by caller.
try {
Stream in =
- new Stream(socket.getInputStream(), elementType);
+ new Stream(socket.getInputStream(), elementType, third);
Stream out =
- new Stream(socket.getOutputStream(), elementType);
+ new Stream(socket.getOutputStream(), elementType, third);
return new SocketStream(socket, in, out);
}
catch (Exception e) {
More information about the armedbear-cvs
mailing list