diff src/goodjava/io/IoUtils.java @ 1493:471ef3e6a84e

more io
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 May 2020 00:12:15 -0600
parents af55cfad6e12
children 91c167099462
line wrap: on
line diff
--- a/src/goodjava/io/IoUtils.java	Sat May 02 22:25:56 2020 -0600
+++ b/src/goodjava/io/IoUtils.java	Sun May 03 00:12:15 2020 -0600
@@ -1,6 +1,8 @@
 package goodjava.io;
 
 import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.IOException;
 import java.nio.file.Files;
 
@@ -33,4 +35,17 @@
 		Files.createLink( to.toPath(), from.toPath() );
 	}
 
+	public static long copyAll(InputStream in,OutputStream out)
+		throws IOException
+	{
+		long total = 0;
+		byte[] a = new byte[8192];
+		int n;
+		while( (n=in.read(a)) != -1 ) {
+			out.write(a,0,n);
+			total += n;
+		}
+		return total;
+	}
+
 }
\ No newline at end of file