[armedbear-cvs] r11407 - in branches/open-external-format/src/org/armedbear/lisp: . util
Erik Huelsmann
ehuelsmann at common-lisp.net
Sun Nov 30 21:54:52 UTC 2008
Author: ehuelsmann
Date: Sun Nov 30 21:54:52 2008
New Revision: 11407
Log:
Allow for null ENCODING values: they mean "default".
Modified:
branches/open-external-format/src/org/armedbear/lisp/socket.lisp
branches/open-external-format/src/org/armedbear/lisp/socket_stream.java
branches/open-external-format/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java
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 Sun Nov 30 21:54:52 2008
@@ -31,7 +31,7 @@
(in-package "SYSTEM")
-(defun get-socket-stream (socket &key (element-type '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."
(cond ((eq element-type 'character))
((equal element-type '(unsigned-byte 8)))
@@ -39,7 +39,7 @@
(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 Sun Nov 30 21:54:52 2008
@@ -40,19 +40,38 @@
{
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)
+ static final private Symbol keywordCodePage = Packages.internKeyword("CODE-PAGE");
+
+ public LispObject execute(LispObject first, LispObject second, LispObject third)
throws ConditionThrowable
{
Socket socket = (Socket) ((JavaObject)first).getObject();
LispObject elementType = second; // Checked by caller.
+ LispObject externalFormat = third;
+ String encoding = "ISO-8859-1"; // for default
+ if (externalFormat != NIL) {
+ if (externalFormat instanceof Symbol) {
+ Symbol enc = (Symbol)externalFormat; //FIXME: class cast exception to be caught
+ if (enc != NIL) {
+ if (enc != keywordCodePage) {
+ encoding = enc.getName();
+ }
+ //FIXME: the else for the keywordCodePage to be filled in
+ }
+ //FIXME: the else for the == NIL to be filled in: raise an error...
+ } else if (externalFormat instanceof AbstractString) {
+ AbstractString encName = (AbstractString) externalFormat;
+ encoding = encName.getStringValue();
+ }
+ }
try {
Stream in =
- new Stream(socket.getInputStream(), elementType);
+ new Stream(socket.getInputStream(), elementType, encoding);
Stream out =
- new Stream(socket.getOutputStream(), elementType);
+ new Stream(socket.getOutputStream(), elementType, encoding);
return new SocketStream(socket, in, out);
}
catch (Exception e) {
Modified: branches/open-external-format/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java (original)
+++ branches/open-external-format/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java Sun Nov 30 21:54:52 2008
@@ -173,8 +173,8 @@
fcn = raf.getChannel();
fcnpos = fcn.position();
fcnsize = fcn.size();
-
- cset = Charset.forName(encoding);
+
+ cset = (encoding == null) ? Charset.defaultCharset() : Charset.forName(encoding);
cdec = cset.newDecoder();
cenc = cset.newEncoder();
More information about the armedbear-cvs
mailing list