diff 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
line wrap: on
line diff
--- a/src/goodjava/rpc/RpcCon.java	Sun May 03 00:12:15 2020 -0600
+++ b/src/goodjava/rpc/RpcCon.java	Sun May 03 11:51:31 2020 -0600
@@ -12,6 +12,7 @@
 import goodjava.io.DataInputStream;
 import goodjava.io.DataOutputStream;
 import goodjava.io.IoUtils;
+import goodjava.io.CountingInputStream;
 
 
 public class RpcCon {
@@ -57,10 +58,12 @@
 		try {
 			out.writeString(json);
 			if( in != null ) {
-				long total = IoUtils.copyAll(in,out);
-				if( total != lenIn ) {
+				CountingInputStream countIn = new CountingInputStream(in);
+				IoUtils.copyAll(countIn,out);
+				countIn.close();
+				if( countIn.count() != lenIn ) {
 					close();
-					throw new RpcError("InputStream wrong length "+total+" when should be "+lenIn);
+					throw new RpcError("InputStream wrong length "+countIn.count()+" when should be "+lenIn);
 				}
 			}
 			out.flush();