That's a great way :) +1
On 12/6/01 7:08 PM, "Michael Bayne" <[EMAIL PROTECTED]> wrote: > I've been using commons/util for some projects and inevitably end up > extending the useful utility classes provided therein. I've been putting > these in my own utility library, but I'd like to contribute back to > commons/util where appropriate. > > What would be the procedure for doing this? > > Here's a patch for starters: > > Index: src/java/org/apache/commons/util/StreamUtils.java > =================================================================== > RCS file: > /home/cvspublic/jakarta-commons-sandbox/util/src/java/org/apache/commons/util/ > StreamUtils.java,v > retrieving revision 1.2 > diff -u -p -r1.2 StreamUtils.java > --- src/java/org/apache/commons/util/StreamUtils.java 2001/08/15 22:57:03 1.2 > +++ src/java/org/apache/commons/util/StreamUtils.java 2001/12/06 23:48:58 > @@ -104,6 +104,40 @@ public class StreamUtils > String encoding) > throws IOException > { > + ByteArrayOutputStream contents = readStream(toRead, bufferSize); > + return (encoding == null ? contents.toString() : > + contents.toString(encoding)); > + } > + > + /** > + * Reads from a stream until EOF, and returns the bytes read. > + * > + * @param toRead Stream to use as source. > + * @param bufferSize Size of buffer to use when reading from source. > + * @return The contents of <code>toRead</code>. > + */ > + public static byte[] streamAsBytes(InputStream toRead, int bufferSize, > + String encoding) > + throws IOException > + { > + ByteArrayOutputStream contents = readStream(toRead, bufferSize); > + return contents.toByteArray(); > + } > + > + /** > + * Reads from a stream util EOF, placing the resulting data into a > + * <code>ByteArrayOutputStream</code> which is subsequently returned. > + * > + * @param toRead Stream to use as source. > + * @param bufferSize Size of buffer to use when reading from source. > + * > + * @return a <code>ByteArrayOutputStream</code> containing the > + * contents of <code>toRead</code>. > + */ > + protected static ByteArrayOutputStream readStream(InputStream toRead, > + int bufferSize) > + throws IOException > + { > ByteArrayOutputStream contents = new ByteArrayOutputStream(); > byte[] buffer = new byte[bufferSize]; > int bytesRead; > @@ -113,8 +147,7 @@ public class StreamUtils > contents.write(buffer, 0, bytesRead); > } > > - return (encoding == null ? contents.toString() : > - contents.toString(encoding)); > + return contents; > } > > /** > > Thanks, > > -- mdb /o)\ Well, I'll be a greased Jesus! > \(o/ > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > -- Geir Magnusson Jr. [EMAIL PROTECTED] System and Software Consulting "Whoever would overthrow the liberty of a nation must begin by subduing the freeness of speech." - Benjamin Franklin -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>