Mercurial Hosting > luan
view src/luan/lib/PickleServer.java @ 145:90f38a5d0e0a
add Os.File
git-svn-id: https://luan-java.googlecode.com/svn/trunk@146 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 15 Jun 2014 10:02:16 +0000 |
parents | 486a0641bca4 |
children | 0517a4a7fcc5 |
line wrap: on
line source
package luan.lib; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.EOFException; import java.util.List; import java.util.ArrayList; import luan.Luan; import luan.LuanState; import luan.LuanException; final class PickleServer { private final PickleCon con; PickleServer(LuanState luan,DataInputStream in,DataOutputStream out) { con = new PickleCon(luan,in,out); } void next() throws IOException { try { List<String> list = new ArrayList<String>(); try { Object[] result = Luan.array(con.read()); list.add( "return true" ); for( Object obj : result ) { list.add( ", " ); list.add( con.pickle(obj) ); } } catch(LuanException e) { //e.printStackTrace(); list.add( "return false, " ); list.add( con.pickle(e.getMessage()) ); list.add( ", " ); list.add( con.pickle(con.src) ); } list.add( "\n" ); con.write( list.toArray() ); } catch(LuanException e2) { throw new RuntimeException(e2); } } public void run() { try { while( true ) { next(); } } catch(EOFException e) { // done } catch(IOException e) { e.printStackTrace(); } try { con.close(); } catch(IOException e) { throw new RuntimeException(e); } } }