[armedbear-cvs] r13917 - trunk/abcl/src/org/armedbear/lisp
mevenson at common-lisp.net
mevenson at common-lisp.net
Mon Apr 16 22:09:15 UTC 2012
Author: mevenson
Date: Mon Apr 16 15:09:14 2012
New Revision: 13917
Log:
SYS:AVAILABLE-ENCODINGS returns a list of formats suitable for stream construction.
The implementation may actually accept additional synonyms, but they
will all be mapped to these underlying encodings native to the hosting
JVM.
The contents of this list are JVM implementation dependent.
Modified:
trunk/abcl/src/org/armedbear/lisp/Stream.java
Modified: trunk/abcl/src/org/armedbear/lisp/Stream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Stream.java Mon Apr 16 14:24:36 2012 (r13916)
+++ trunk/abcl/src/org/armedbear/lisp/Stream.java Mon Apr 16 15:09:14 2012 (r13917)
@@ -50,6 +50,11 @@
import java.nio.charset.Charset;
import java.util.BitSet;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.SortedMap;
+import java.util.Set;
+
import org.armedbear.lisp.util.DecodingReader;
/** The stream class
@@ -142,6 +147,7 @@
public Stream(Symbol structureClass, InputStream inputStream, LispObject elementType) {
this(structureClass, inputStream, elementType, keywordDefault);
}
+
// Input stream constructors.
@@ -330,6 +336,35 @@
((DecodingReader)reader).setCharset(Charset.forName(encoding));
}
+
+ public static final Primitive AVAILABLE_ENCODINGS = new pf_available_encodings();
+ @DocString(name="available-encodings",
+ returns="encodings",
+ doc="Returns all charset encodings suitable for passing to a stream constructor available at runtime.")
+ private static final class pf_available_encodings extends Primitive {
+ pf_available_encodings() {
+ super("available-encodings", PACKAGE_SYS, true);
+ }
+ public LispObject execute() {
+ LispObject result = NIL;
+ for (Symbol encoding : availableEncodings()) {
+ result = result.push(encoding);
+ }
+ return result.nreverse();
+ }
+ }
+
+ static public List<Symbol> availableEncodings() {
+ List<Symbol> result = new LinkedList<Symbol>();
+
+ SortedMap<String, Charset> available = Charset.availableCharsets();
+ Set<String> encodings = available.keySet();
+ for (String charset : encodings) {
+ result.add(new Symbol(charset));
+ }
+ return result;
+ }
+
public boolean isOpen() {
return open;
}
More information about the armedbear-cvs
mailing list