comparison src/luan/lib/IoLib.java @ 147:cc3a0578edac

fix Io.reverse_pickle git-svn-id: https://luan-java.googlecode.com/svn/trunk@148 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 15 Jun 2014 15:41:36 +0000
parents 90f38a5d0e0a
children 78ba371ea1e9
comparison
equal deleted inserted replaced
146:0517a4a7fcc5 147:cc3a0578edac
210 210
211 211
212 212
213 public static abstract class LuanIn { 213 public static abstract class LuanIn {
214 abstract InputStream inputStream() throws IOException; 214 abstract InputStream inputStream() throws IOException;
215 public abstract String name(); 215 public abstract String to_string();
216 216
217 public String read_text() throws IOException { 217 public String read_text() throws IOException {
218 Reader in = new InputStreamReader(inputStream()); 218 Reader in = new InputStreamReader(inputStream());
219 String s = Utils.readAll(in); 219 String s = Utils.readAll(in);
220 in.close(); 220 in.close();
238 } 238 }
239 239
240 LuanTable table() { 240 LuanTable table() {
241 LuanTable tbl = new LuanTable(); 241 LuanTable tbl = new LuanTable();
242 try { 242 try {
243 tbl.put( "name", new LuanJavaFunction( 243 tbl.put( "to_string", new LuanJavaFunction(
244 LuanIn.class.getMethod( "name" ), this 244 LuanIn.class.getMethod( "to_string" ), this
245 ) ); 245 ) );
246 tbl.put( "read_text", new LuanJavaFunction( 246 tbl.put( "read_text", new LuanJavaFunction(
247 LuanIn.class.getMethod( "read_text" ), this 247 LuanIn.class.getMethod( "read_text" ), this
248 ) ); 248 ) );
249 tbl.put( "read_binary", new LuanJavaFunction( 249 tbl.put( "read_binary", new LuanJavaFunction(
319 319
320 @Override InputStream inputStream() throws IOException { 320 @Override InputStream inputStream() throws IOException {
321 return url.openStream(); 321 return url.openStream();
322 } 322 }
323 323
324 @Override public String name() { 324 @Override public String to_string() {
325 return url.toString(); 325 return url.toString();
326 } 326 }
327 } 327 }
328 328
329 public static final class LuanFile extends LuanIO { 329 public static final class LuanFile extends LuanIO {
343 343
344 @Override OutputStream outputStream() throws IOException { 344 @Override OutputStream outputStream() throws IOException {
345 return new FileOutputStream(file); 345 return new FileOutputStream(file);
346 } 346 }
347 347
348 @Override public String name() { 348 @Override public String to_string() {
349 return file.toString(); 349 return file.toString();
350 } 350 }
351 351
352 public LuanTable os_file() { 352 public LuanTable os_file() {
353 return new OsLib.LuanFile(file).table(); 353 return new OsLib.LuanFile(file).table();
400 400
401 @Override OutputStream outputStream() throws IOException { 401 @Override OutputStream outputStream() throws IOException {
402 return socket.getOutputStream(); 402 return socket.getOutputStream();
403 } 403 }
404 404
405 @Override public String name() { 405 @Override public String to_string() {
406 return socket.toString(); 406 return socket.toString();
407 } 407 }
408 408
409 public LuanTable Pickle_client(LuanState luan) throws IOException { 409 public LuanTable Pickle_client(LuanState luan) throws IOException {
410 DataInputStream in = new DataInputStream(new BufferedInputStream(inputStream())); 410 DataInputStream in = new DataInputStream(new BufferedInputStream(inputStream()));