Mercurial Hosting > luan
comparison core/src/luan/modules/IoLuan.java @ 705:52ecb629a634
add to_uri_string()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 May 2016 16:42:47 -0600 |
parents | d0280c7fdc3a |
children | 30c87c859277 |
comparison
equal
deleted
inserted
replaced
704:90c89138c234 | 705:52ecb629a634 |
---|---|
166 | 166 |
167 | 167 |
168 public static abstract class LuanIn { | 168 public static abstract class LuanIn { |
169 abstract InputStream inputStream() throws IOException; | 169 abstract InputStream inputStream() throws IOException; |
170 public abstract String to_string(); | 170 public abstract String to_string(); |
171 public abstract String to_uri_string(); | |
171 | 172 |
172 public Reader reader() throws IOException { | 173 public Reader reader() throws IOException { |
173 return new InputStreamReader(inputStream()); | 174 return new InputStreamReader(inputStream()); |
174 } | 175 } |
175 | 176 |
210 try { | 211 try { |
211 tbl.rawPut( "java", this ); | 212 tbl.rawPut( "java", this ); |
212 tbl.rawPut( "to_string", new LuanJavaFunction( | 213 tbl.rawPut( "to_string", new LuanJavaFunction( |
213 LuanIn.class.getMethod( "to_string" ), this | 214 LuanIn.class.getMethod( "to_string" ), this |
214 ) ); | 215 ) ); |
216 tbl.rawPut( "to_uri_string", new LuanJavaFunction( | |
217 LuanIn.class.getMethod( "to_uri_string" ), this | |
218 ) ); | |
215 tbl.rawPut( "read_text", new LuanJavaFunction( | 219 tbl.rawPut( "read_text", new LuanJavaFunction( |
216 LuanIn.class.getMethod( "read_text" ), this | 220 LuanIn.class.getMethod( "read_text" ), this |
217 ) ); | 221 ) ); |
218 tbl.rawPut( "read_binary", new LuanJavaFunction( | 222 tbl.rawPut( "read_binary", new LuanJavaFunction( |
219 LuanIn.class.getMethod( "read_binary" ), this | 223 LuanIn.class.getMethod( "read_binary" ), this |
240 return System.in; | 244 return System.in; |
241 } | 245 } |
242 | 246 |
243 @Override public String to_string() { | 247 @Override public String to_string() { |
244 return "<stdin>"; | 248 return "<stdin>"; |
249 } | |
250 | |
251 @Override public String to_uri_string() { | |
252 return "stdin:"; | |
245 } | 253 } |
246 | 254 |
247 @Override public String read_text() throws IOException { | 255 @Override public String read_text() throws IOException { |
248 return Utils.readAll(new InputStreamReader(System.in)); | 256 return Utils.readAll(new InputStreamReader(System.in)); |
249 } | 257 } |
325 | 333 |
326 @Override public String to_string() { | 334 @Override public String to_string() { |
327 return "<null>"; | 335 return "<null>"; |
328 } | 336 } |
329 | 337 |
338 @Override public String to_uri_string() { | |
339 return "null:"; | |
340 } | |
341 | |
330 }; | 342 }; |
331 | 343 |
332 public static final class LuanString extends LuanIO { | 344 public static final class LuanString extends LuanIO { |
333 private String s; | 345 private String s; |
334 | 346 |
344 throw new UnsupportedOperationException(); | 356 throw new UnsupportedOperationException(); |
345 } | 357 } |
346 | 358 |
347 @Override public String to_string() { | 359 @Override public String to_string() { |
348 return "<string>"; | 360 return "<string>"; |
361 } | |
362 | |
363 @Override public String to_uri_string() { | |
364 return "string:" + s; | |
349 } | 365 } |
350 | 366 |
351 @Override public Reader reader() { | 367 @Override public Reader reader() { |
352 return new StringReader(s); | 368 return new StringReader(s); |
353 } | 369 } |
391 | 407 |
392 @Override public String to_string() { | 408 @Override public String to_string() { |
393 return url.toString(); | 409 return url.toString(); |
394 } | 410 } |
395 | 411 |
412 @Override public String to_uri_string() { | |
413 return url.toString(); | |
414 } | |
415 | |
396 public String post(String postS) throws IOException { | 416 public String post(String postS) throws IOException { |
397 return new UrlCall(url).post(postS); | 417 return new UrlCall(url).post(postS); |
398 } | 418 } |
399 | 419 |
400 @Override public LuanTable table() { | 420 @Override public LuanTable table() { |
430 return new FileOutputStream(file); | 450 return new FileOutputStream(file); |
431 } | 451 } |
432 | 452 |
433 @Override public String to_string() { | 453 @Override public String to_string() { |
434 return file.toString(); | 454 return file.toString(); |
455 } | |
456 | |
457 @Override public String to_uri_string() { | |
458 return "file:" + file.toString(); | |
435 } | 459 } |
436 | 460 |
437 public LuanTable child(LuanState luan,String name) throws LuanException { | 461 public LuanTable child(LuanState luan,String name) throws LuanException { |
438 return new LuanFile(luan,new File(file,name)).table(); | 462 return new LuanFile(luan,new File(file,name)).table(); |
439 } | 463 } |
641 } | 665 } |
642 | 666 |
643 @Override public String to_string() { | 667 @Override public String to_string() { |
644 return socket.toString(); | 668 return socket.toString(); |
645 } | 669 } |
670 | |
671 @Override public String to_uri_string() { | |
672 throw new UnsupportedOperationException(); | |
673 } | |
646 } | 674 } |
647 | 675 |
648 public static LuanTable socket(String name) throws LuanException, IOException { | 676 public static LuanTable socket(String name) throws LuanException, IOException { |
649 int i = name.indexOf(':'); | 677 int i = name.indexOf(':'); |
650 if( i == -1 ) | 678 if( i == -1 ) |