Mercurial Hosting > luan
changeset 2003:f777348734b6 default tip
add write_from
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 24 Jul 2025 22:04:08 -0600 |
parents | 59ad4e136809 |
children | |
files | src/luan/modules/Boot.luan src/luan/modules/IoLuan.java |
diffstat | 2 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/Boot.luan Thu Jul 24 17:03:21 2025 -0600 +++ b/src/luan/modules/Boot.luan Thu Jul 24 22:04:08 2025 -0600 @@ -88,6 +88,11 @@ this.java = writer this.write = writer.write this.close = writer.close + + function this.write_from(reader) + reader.java.writeTo(writer) + end + return this end
--- a/src/luan/modules/IoLuan.java Thu Jul 24 17:03:21 2025 -0600 +++ b/src/luan/modules/IoLuan.java Thu Jul 24 22:04:08 2025 -0600 @@ -216,6 +216,21 @@ public void set_charset(String charset) { this.charset = charset; } + + public void writeTo(Object obj) throws IOException, LuanException { + if( obj instanceof OutputStream ) { + OutputStream out = (OutputStream)obj; + InputStream in = inputStream(); + IoUtils.copyAll(in,out); + in.close(); + } else if( obj instanceof Writer ) { + Writer out = (Writer)obj; + Reader in = reader(); + IoUtils.copyAll(in,out); + in.close(); + } else + throw new LuanException("invalid type: "+obj); + } } public static final LuanIn defaultStdin = new LuanIn() {