Mercurial Hosting > luan
comparison src/goodjava/rpc/RpcCon.java @ 1494:91c167099462
more io
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 May 2020 11:51:31 -0600 |
parents | 471ef3e6a84e |
children | 22e15cf73040 |
comparison
equal
deleted
inserted
replaced
1493:471ef3e6a84e | 1494:91c167099462 |
---|---|
10 import goodjava.json.JsonToString; | 10 import goodjava.json.JsonToString; |
11 import goodjava.io.BufferedInputStream; | 11 import goodjava.io.BufferedInputStream; |
12 import goodjava.io.DataInputStream; | 12 import goodjava.io.DataInputStream; |
13 import goodjava.io.DataOutputStream; | 13 import goodjava.io.DataOutputStream; |
14 import goodjava.io.IoUtils; | 14 import goodjava.io.IoUtils; |
15 import goodjava.io.CountingInputStream; | |
15 | 16 |
16 | 17 |
17 public class RpcCon { | 18 public class RpcCon { |
18 private final Socket socket; | 19 private final Socket socket; |
19 private final DataInputStream in; | 20 private final DataInputStream in; |
55 list.add(0,lenIn); | 56 list.add(0,lenIn); |
56 String json = new JsonToString().toString(list); | 57 String json = new JsonToString().toString(list); |
57 try { | 58 try { |
58 out.writeString(json); | 59 out.writeString(json); |
59 if( in != null ) { | 60 if( in != null ) { |
60 long total = IoUtils.copyAll(in,out); | 61 CountingInputStream countIn = new CountingInputStream(in); |
61 if( total != lenIn ) { | 62 IoUtils.copyAll(countIn,out); |
63 countIn.close(); | |
64 if( countIn.count() != lenIn ) { | |
62 close(); | 65 close(); |
63 throw new RpcError("InputStream wrong length "+total+" when should be "+lenIn); | 66 throw new RpcError("InputStream wrong length "+countIn.count()+" when should be "+lenIn); |
64 } | 67 } |
65 } | 68 } |
66 out.flush(); | 69 out.flush(); |
67 } catch(IOException e) { | 70 } catch(IOException e) { |
68 close(); | 71 close(); |