[Webfunds-commits] java/webfunds/util Support.java
Ian Grigg
iang@cypherpunks.ai
Sun, 15 Apr 2001 13:32:23 -0400 (AST)
iang 01/04/15 13:32:23
Modified: webfunds/util Support.java
Log:
whoops, forgot this one!
Revision Changes Path
1.4 +30 -0 java/webfunds/util/Support.java
Index: Support.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/util/Support.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Support.java 2001/04/15 05:29:59 1.3
+++ Support.java 2001/04/15 17:32:23 1.4
@@ -1,5 +1,5 @@
/*
- * $Id: Support.java,v 1.3 2001/04/15 05:29:59 iang Exp $
+ * $Id: Support.java,v 1.4 2001/04/15 17:32:23 iang Exp $
*
* Copyright (c) 2000-2001 Systemics Inc on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -87,4 +87,34 @@
return baos.toByteArray();
}
+
+ public static void copyStreamToStream(InputStream is, OutputStream os)
+ throws IOException
+ {
+ int size = 10240;
+ byte[] buf = new byte[size];
+
+ int offset = 0;
+ while (is.available() >= 0)
+ {
+ int i;
+ i = is.read(buf, offset, size - offset);
+ if (i == -1) // EOF!
+ break ;
+ if (i <= 0)
+ throw new IOException("read returned " + i);
+// logmsg("i == " + i + "; offset == " + offset + " (" + size + ")");
+ offset += i;
+ if (offset < size) // partial read?
+ continue ; // keep reading until full
+
+ os.write(buf);
+ offset = 0;
+ }
+
+ if (offset > 0)
+ os.write(buf, 0, offset);
+ os.flush();
+ }
+
}