diff src/luan/modules/IoLuan.java @ 1335:e0cf0d108a77

major cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Feb 2019 03:10:45 -0700
parents c88b486a9511
children 0cceff521abb
line wrap: on
line diff
--- a/src/luan/modules/IoLuan.java	Tue Feb 12 22:53:57 2019 -0700
+++ b/src/luan/modules/IoLuan.java	Thu Feb 14 03:10:45 2019 -0700
@@ -89,8 +89,8 @@
 	}
 
 	static LuanFunction lines(final BufferedReader in) {
-		return new LuanFunction() {
-			@Override public Object call(Luan luan,Object[] args) throws LuanException {
+		return new LuanFunction(false) {
+			@Override public Object call(Object[] args) throws LuanException {
 				try {
 					if( args.length > 0 ) {
 						if( args.length > 1 || !"close".equals(args[0]) )
@@ -110,10 +110,10 @@
 	}
 
 	static LuanFunction blocks(final InputStream in,final int blockSize) {
-		return new LuanFunction() {
+		return new LuanFunction(false) {
 			final byte[] a = new byte[blockSize];
 
-			@Override public Object call(Luan luan,Object[] args) throws LuanException {
+			@Override public Object call(Object[] args) throws LuanException {
 				try {
 					if( args.length > 0 ) {
 						if( args.length > 1 || !"close".equals(args[0]) )
@@ -153,41 +153,41 @@
 	public static abstract class LuanIn {
 		protected String charset = null;
 
-		public abstract InputStream inputStream(Luan luan) throws IOException, LuanException;
+		public abstract InputStream inputStream() throws IOException, LuanException;
 		public abstract String to_string();
 		public abstract String to_uri_string();
 
-		public Reader reader(Luan luan) throws IOException, LuanException {
-			InputStream in = inputStream(luan);
+		public Reader reader() throws IOException, LuanException {
+			InputStream in = inputStream();
 			return charset==null ? new InputStreamReader(in) : new InputStreamReader(in,charset);
 		}
 
-		public String read_text(Luan luan) throws IOException, LuanException {
-			Reader in = reader(luan);
+		public String read_text() throws IOException, LuanException {
+			Reader in = reader();
 			String s = Utils.readAll(in);
 			in.close();
 			return s;
 		}
 
-		public byte[] read_binary(Luan luan) throws IOException, LuanException {
-			InputStream in = inputStream(luan);
+		public byte[] read_binary() throws IOException, LuanException {
+			InputStream in = inputStream();
 			byte[] a = Utils.readAll(in);
 			in.close();
 			return a;
 		}
 
-		public LuanFunction read_lines(Luan luan) throws IOException, LuanException {
-			return lines(new BufferedReader(reader(luan)));
+		public LuanFunction read_lines() throws IOException, LuanException {
+			return lines(new BufferedReader(reader()));
 		}
 
-		public LuanFunction read_blocks(Luan luan,Integer blockSize) throws IOException, LuanException {
+		public LuanFunction read_blocks(Integer blockSize) throws IOException, LuanException {
 			int n = blockSize!=null ? blockSize : Utils.bufSize;
-			return blocks(inputStream(luan),n);
+			return blocks(inputStream(),n);
 		}
 
-		public boolean exists(Luan luan) throws IOException, LuanException {
+		public boolean exists() throws IOException, LuanException {
 			try {
-				inputStream(luan).close();
+				inputStream().close();
 				return true;
 			} catch(FileNotFoundException e) {
 				return false;
@@ -196,9 +196,9 @@
 			}
 		}
 
-		public long checksum(Luan luan) throws IOException, LuanException {
+		public long checksum() throws IOException, LuanException {
 			long cs = 0;
-			InputStream in = new BufferedInputStream(inputStream(luan));
+			InputStream in = new BufferedInputStream(inputStream());
 			int c;
 			while( (c=in.read()) != -1 ) {
 				cs = 31 * cs + c;
@@ -218,7 +218,7 @@
 
 	public static final LuanIn defaultStdin = new LuanIn() {
 
-		@Override public InputStream inputStream(Luan luan) {
+		@Override public InputStream inputStream() {
 			return System.in;
 		}
 
@@ -230,15 +230,15 @@
 			return "stdin:";
 		}
 
-		@Override public String read_text(Luan luan) throws IOException {
+		@Override public String read_text() throws IOException {
 			return Utils.readAll(new InputStreamReader(System.in));
 		}
 
-		@Override public byte[] read_binary(Luan luan) throws IOException {
+		@Override public byte[] read_binary() throws IOException {
 			return Utils.readAll(System.in);
 		}
 
-		@Override public boolean exists(Luan luan) {
+		@Override public boolean exists() {
 			return true;
 		}
 	};
@@ -251,7 +251,7 @@
 			return charset==null ? new OutputStreamWriter(out) : new OutputStreamWriter(out,charset);
 		}
 
-		public void write(Luan luan,Object obj) throws LuanException, IOException {
+		public void write(Object obj) throws LuanException, IOException {
 			if( obj instanceof String ) {
 				String s = (String)obj;
 				Writer out = writer();
@@ -271,7 +271,7 @@
 				Object java = t.rawGet("java");
 				if( java instanceof LuanIn ) {
 					LuanIn luanIn = (LuanIn)java;
-					InputStream in = luanIn.inputStream(luan);
+					InputStream in = luanIn.inputStream();
 					OutputStream out = outputStream();
 					Utils.copyAll(in,out);
 					out.close();
@@ -290,9 +290,9 @@
 			return new BufferedOutputStream(outputStream());
 		}
 
-		public void write_text(Luan luan,Object... args) throws LuanException, IOException {
+		public void write_text(Object... args) throws LuanException, IOException {
 			LuanWriter luanWriter = luanWriter(new BufferedWriter(writer()));
-			luanWriter.write(luan,args);
+			luanWriter.write(args);
 			luanWriter.close();
 		}
 	}
@@ -307,7 +307,7 @@
 			@Override public void write(int b) {}
 		};
 
-		@Override public InputStream inputStream(Luan luan) {
+		@Override public InputStream inputStream() {
 			return in;
 		}
 
@@ -333,7 +333,7 @@
 			this.s = s;
 		}
 
-		@Override public InputStream inputStream(Luan luan) {
+		@Override public InputStream inputStream() {
 			throw new UnsupportedOperationException();
 		}
 
@@ -349,15 +349,15 @@
 			return "string:" + s;
 		}
 
-		@Override public Reader reader(Luan luan) {
+		@Override public Reader reader() {
 			return new StringReader(s);
 		}
 
-		@Override public String read_text(Luan luan) {
+		@Override public String read_text() {
 			return s;
 		}
 
-		@Override public boolean exists(Luan luan) {
+		@Override public boolean exists() {
 			return true;
 		}
 
@@ -398,7 +398,7 @@
 			this.file = file;
 		}
 
-		@Override public InputStream inputStream(Luan luan) throws IOException {
+		@Override public InputStream inputStream() throws IOException {
 			return new FileInputStream(file);
 		}
 
@@ -436,7 +436,7 @@
 			return new LuanFile(luan,parent);
 		}
 
-		@Override public boolean exists(Luan luan) {
+		@Override public boolean exists() {
 			return file.exists();
 		}
 
@@ -546,7 +546,7 @@
 			this.dir = dir;
 		}
 
-		@Override public InputStream inputStream(Luan luan) throws IOException {
+		@Override public InputStream inputStream() throws IOException {
 			return proc.getInputStream();
 		}
 
@@ -562,7 +562,7 @@
 			throw new UnsupportedOperationException();
 		}
 
-		@Override public boolean exists(Luan luan) {
+		@Override public boolean exists() {
 			return true;
 		}
 
@@ -583,8 +583,8 @@
 			}
 		}
 
-		@Override public String read_text(Luan luan) throws IOException, LuanException {
-			String s = super.read_text(luan);
+		@Override public String read_text() throws IOException, LuanException {
+			String s = super.read_text();
 			wait_for();
 			return s;
 		}
@@ -614,7 +614,7 @@
 			this.in = in;
 		}
 
-		@Override public InputStream inputStream(Luan luan) {
+		@Override public InputStream inputStream() {
 			return in;
 		}
 
@@ -626,7 +626,7 @@
 			throw new UnsupportedOperationException();
 		}
 
-		@Override public boolean exists(Luan luan) {
+		@Override public boolean exists() {
 			return true;
 		}
 	};