comparison core/src/luan/modules/IoLuan.java @ 263:54873a389f80

add "http" and "https" protocols git-svn-id: https://luan-java.googlecode.com/svn/trunk@264 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 29 Oct 2014 00:02:14 +0000
parents 3ccc5205d04d
children 9e0d4452e649
comparison
equal deleted inserted replaced
262:3ccc5205d04d 263:54873a389f80
299 } 299 }
300 300
301 public static final class LuanUrl extends LuanIn { 301 public static final class LuanUrl extends LuanIn {
302 private final URL url; 302 private final URL url;
303 303
304 private LuanUrl(URL url) throws LuanException { 304 private LuanUrl(URL url) {
305 this.url = url; 305 this.url = url;
306 } 306 }
307 307
308 @Override InputStream inputStream() throws IOException { 308 @Override InputStream inputStream() throws IOException {
309 return url.openStream(); 309 return url.openStream();
430 if( url == null ) 430 if( url == null )
431 return null; 431 return null;
432 return new LuanUrl(url).table(); 432 return new LuanUrl(url).table();
433 } 433 }
434 434
435 private static LuanTable url(String url) throws IOException {
436 return new LuanUrl(new URL(url)).table();
437 }
438
439 public static LuanTable http(String path) throws IOException {
440 return url("http:"+path);
441 }
442
443 public static LuanTable https(String path) throws IOException {
444 return url("https:"+path);
445 }
446
435 private static LuanTable newProtocols() { 447 private static LuanTable newProtocols() {
436 LuanTable protocols = Luan.newTable(); 448 LuanTable protocols = Luan.newTable();
437 try { 449 try {
438 add( protocols, "file", LuanState.class, String.class ); 450 add( protocols, "file", LuanState.class, String.class );
439 add( protocols, "classpath", LuanState.class, String.class ); 451 add( protocols, "classpath", LuanState.class, String.class );
440 add( protocols, "socket", LuanState.class, String.class ); 452 add( protocols, "socket", LuanState.class, String.class );
453 add( protocols, "http", String.class );
454 add( protocols, "https", String.class );
441 } catch(NoSuchMethodException e) { 455 } catch(NoSuchMethodException e) {
442 throw new RuntimeException(e); 456 throw new RuntimeException(e);
443 } 457 }
444 return protocols; 458 return protocols;
445 } 459 }