comparison src/luan/modules/IoLuan.java @ 1563:8fbcc4747091

remove LuanFunction.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 09 Nov 2020 01:37:57 -0700
parents b89212fd04b5
children c922446f53aa
comparison
equal deleted inserted replaced
1562:b89212fd04b5 1563:8fbcc4747091
48 } 48 }
49 49
50 50
51 public interface LuanWriter { 51 public interface LuanWriter {
52 public Object out(); 52 public Object out();
53 public void write(Object... args) throws LuanException, IOException; 53 public void write(Luan luan,Object... args) throws LuanException, IOException;
54 public void close() throws IOException; 54 public void close() throws IOException;
55 } 55 }
56 56
57 public static LuanWriter luanWriter(final PrintStream out) { 57 public static LuanWriter luanWriter(final PrintStream out) {
58 return new LuanWriter() { 58 return new LuanWriter() {
59 59
60 public Object out() { 60 public Object out() {
61 return out; 61 return out;
62 } 62 }
63 63
64 public void write(Object... args) throws LuanException { 64 public void write(Luan luan,Object... args) throws LuanException {
65 for( Object obj : args ) { 65 for( Object obj : args ) {
66 out.print( Luan.luanToString(obj) ); 66 out.print( luan.luanToString(obj) );
67 } 67 }
68 } 68 }
69 69
70 public void close() { 70 public void close() {
71 out.close(); 71 out.close();
78 78
79 public Object out() { 79 public Object out() {
80 return out; 80 return out;
81 } 81 }
82 82
83 public void write(Object... args) throws LuanException, IOException { 83 public void write(Luan luan,Object... args) throws LuanException, IOException {
84 for( Object obj : args ) { 84 for( Object obj : args ) {
85 out.write( Luan.luanToString(obj) ); 85 out.write( luan.luanToString(obj) );
86 } 86 }
87 } 87 }
88 88
89 public void close() throws IOException { 89 public void close() throws IOException {
90 out.close(); 90 out.close();
91 } 91 }
92 }; 92 };
93 } 93 }
94 94
95 static LuanFunction lines(final BufferedReader in) { 95 static LuanFunction lines(final BufferedReader in) {
96 return new LuanFunction(false) { 96 return new LuanFunction() {
97 @Override public Object call(Object[] args) throws LuanException { 97 @Override public Object call(Luan luan,Object[] args) throws LuanException {
98 try { 98 try {
99 if( args.length > 0 ) { 99 if( args.length > 0 ) {
100 if( args.length > 1 || !"close".equals(args[0]) ) 100 if( args.length > 1 || !"close".equals(args[0]) )
101 throw new LuanException( "the only argument allowed is 'close'" ); 101 throw new LuanException( "the only argument allowed is 'close'" );
102 in.close(); 102 in.close();
112 } 112 }
113 }; 113 };
114 } 114 }
115 115
116 static LuanFunction blocks(final InputStream in,final int blockSize) { 116 static LuanFunction blocks(final InputStream in,final int blockSize) {
117 return new LuanFunction(false) { 117 return new LuanFunction() {
118 final byte[] a = new byte[blockSize]; 118 final byte[] a = new byte[blockSize];
119 119
120 @Override public Object call(Object[] args) throws LuanException { 120 @Override public Object call(Luan luan,Object[] args) throws LuanException {
121 try { 121 try {
122 if( args.length > 0 ) { 122 if( args.length > 0 ) {
123 if( args.length > 1 || !"close".equals(args[0]) ) 123 if( args.length > 1 || !"close".equals(args[0]) )
124 throw new LuanException( "the only argument allowed is 'close'" ); 124 throw new LuanException( "the only argument allowed is 'close'" );
125 in.close(); 125 in.close();
288 288
289 public OutputStream binary_writer() throws IOException { 289 public OutputStream binary_writer() throws IOException {
290 return new BufferedOutputStream(outputStream()); 290 return new BufferedOutputStream(outputStream());
291 } 291 }
292 292
293 public void write_text(Object... args) throws LuanException, IOException { 293 public void write_text(Luan luan,Object... args) throws LuanException, IOException {
294 LuanWriter luanWriter = text_writer(); 294 LuanWriter luanWriter = text_writer();
295 luanWriter.write(args); 295 luanWriter.write(luan,args);
296 luanWriter.close(); 296 luanWriter.close();
297 } 297 }
298 298
299 public void write_binary(byte[] bytes) throws LuanException, IOException { 299 public void write_binary(byte[] bytes) throws LuanException, IOException {
300 OutputStream out = binary_writer(); 300 OutputStream out = binary_writer();
373 373
374 public Object out() { 374 public Object out() {
375 return out; 375 return out;
376 } 376 }
377 377
378 public void write(Object... args) throws LuanException, IOException { 378 public void write(Luan luan,Object... args) throws LuanException, IOException {
379 for( Object obj : args ) { 379 for( Object obj : args ) {
380 out.write( Luan.luanToString(obj) ); 380 out.write( luan.luanToString(obj) );
381 } 381 }
382 } 382 }
383 383
384 public void close() throws IOException { 384 public void close() throws IOException {
385 s = out.toString(); 385 s = out.toString();