Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add public method to write an iolist to output stream

  • Loading branch information...
commit 8bdc72db69461def297fecf605b16af7663559b5 1 parent d7acd96
@jetztgradnet jetztgradnet authored krestenkrab committed
Showing with 28 additions and 8 deletions.
  1. +28 −8 src/main/java/erjang/m/erlang/ErlConvert.java
View
36 src/main/java/erjang/m/erlang/ErlConvert.java
@@ -20,6 +20,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.math.BigInteger;
import erjang.BIF;
@@ -280,12 +281,17 @@ public static EBitString iolist_to_binary(EObject list) {
BARR barr = new BARR();
- collectList(list, iol, barr);
+ try {
+ collectList(list, iol, barr);
+ } catch (IOException e) {
+ // should not happen, barr is an byte array stream
+ throw new InternalError();
+ }
return barr.asBinary();
}
- private static void collectList(EObject list, ECons iol, BARR barr) {
+ private static void collectList(EObject list, ECons iol, OutputStream barr) throws IOException {
EObject tail;
ECons cons;
for (tail=iol; (cons = tail.testNonEmptyList()) != null; tail = cons.tail()) {
@@ -299,12 +305,7 @@ private static void collectList(EObject list, ECons iol, BARR barr) {
throw ERT.badarg(list);
barr.write(sm.value);
} else if ((bi = hd.testBinary()) != null) {
- try {
- bi.writeTo(barr);
- } catch (IOException e) {
- // should not happen, barr is an byte array stream
- throw new InternalError();
- }
+ bi.writeTo(barr);
} else if ((co = hd.testNonEmptyList()) != null) {
collectList(list, co, barr);
} else if (hd.isNil()) {
@@ -326,6 +327,25 @@ private static void collectList(EObject list, ECons iol, BARR barr) {
}
}
+ /**
+ * Write io list to output stream.
+ *
+ * @param list io list containing terms to write
+ * @param out output stream
+ * @throws IOException in case of io errors
+ */
+ public static void collectList(EObject list, OutputStream out) throws IOException {
+ ECons iol = list.testCons();
+ if (iol == null)
+ throw ERT.badarg(list);
+
+ if (iol.isNil()) {
+ return;
+ }
+
+ collectList(list, iol, out);
+ }
+
@BIF
public static EObject tuple_to_list(EObject tup) {
ETuple t;
Please sign in to comment.
Something went wrong with that request. Please try again.