Mercurial Hosting > luan
comparison core/src/luan/modules/PickleServer.java @ 281:a1fa4fba99de
change PickleCon to allow any size string
git-svn-id: https://luan-java.googlecode.com/svn/trunk@282 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 26 Nov 2014 04:14:52 +0000 |
parents | 340656b18b74 |
children | 23a93c118042 |
comparison
equal
deleted
inserted
replaced
280:2164b4479661 | 281:a1fa4fba99de |
---|---|
1 package luan.modules; | 1 package luan.modules; |
2 | 2 |
3 import java.io.DataInputStream; | 3 import java.io.InputStream; |
4 import java.io.DataOutputStream; | 4 import java.io.OutputStream; |
5 import java.io.StringWriter; | |
6 import java.io.PrintWriter; | |
5 import java.io.IOException; | 7 import java.io.IOException; |
6 import java.io.EOFException; | 8 import java.io.EOFException; |
7 import java.util.List; | 9 import java.util.List; |
8 import java.util.ArrayList; | 10 import java.util.ArrayList; |
9 import luan.Luan; | 11 import luan.Luan; |
17 public final class PickleServer { | 19 public final class PickleServer { |
18 | 20 |
19 private final PickleCon con; | 21 private final PickleCon con; |
20 private boolean isRunning; | 22 private boolean isRunning; |
21 | 23 |
22 PickleServer(LuanState luan,DataInputStream in,DataOutputStream out) { | 24 PickleServer(LuanState luan,InputStream in,OutputStream out) { |
23 this(new PickleCon(luan,in,out)); | 25 this(new PickleCon(luan,in,out)); |
24 } | 26 } |
25 | 27 |
26 PickleServer(PickleCon con) { | 28 PickleServer(PickleCon con) { |
27 this.con = con; | 29 this.con = con; |
28 } | 30 } |
29 | 31 |
30 void next() throws IOException { | 32 void next() throws IOException { |
31 try { | 33 try { |
32 List<String> list = new ArrayList<String>(); | |
33 try { | 34 try { |
34 Object[] result = Luan.array(con.read()); | 35 Object[] result = Luan.array(con.read()); |
35 list.add( "return true" ); | 36 StringBuilder sb = new StringBuilder(); |
37 sb.append( "return true" ); | |
36 for( Object obj : result ) { | 38 for( Object obj : result ) { |
37 list.add( ", " ); | 39 sb.append( ", " ); |
38 list.add( con.pickle(obj) ); | 40 sb.append( con.pickle(obj) ); |
39 } | 41 } |
42 sb.append( '\n' ); | |
43 con.write( sb.toString() ); | |
40 } catch(LuanException e) { | 44 } catch(LuanException e) { |
41 // System.out.println(e); | 45 // System.out.println(e); |
42 //e.printStackTrace(); | 46 //e.printStackTrace(); |
43 list.add( "return false, " ); | 47 StringBuilder sb = new StringBuilder(); |
44 list.add( con.pickle(e.getMessage()) ); | 48 sb.append( "return false, " ); |
45 list.add( ", " ); | 49 sb.append( con.pickle(e.getMessage()) ); |
46 list.add( con.pickle(con.src) ); | 50 sb.append( ", " ); |
51 sb.append( con.pickle(con.src) ); | |
52 sb.append( '\n' ); | |
53 /* | |
54 Throwable cause = e.getCause(); | |
55 if( cause != null ) { | |
56 sb.append( "\nCaused by: " ); | |
57 StringWriter sw = new StringWriter(); | |
58 cause.printStackTrace(new PrintWriter(sw)); | |
59 sb.append( sw ); | |
60 } | |
61 */ | |
62 con.write( sb.toString() ); | |
47 } | 63 } |
48 list.add( "\n" ); | |
49 con.write( list.toArray() ); | |
50 } catch(LuanException e2) { | 64 } catch(LuanException e2) { |
51 throw new RuntimeException(e2); | 65 throw new RuntimeException(e2); |
52 } | 66 } |
53 } | 67 } |
54 | 68 |