You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Michael Bayne <md...@samskivert.com> on 2001/12/07 01:08:36 UTC

The spirit of sharing

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Avalon/Commons collaboration (Re: The spirit of sharing)

Posted by Jeff Turner <je...@socialchange.net.au>.
On Fri, Dec 07, 2001 at 02:32:00PM -0800, Scott Sanders wrote:
> Jeff,
> 
> I have yet to understand the 'rift' between Avalon and commons, but I
> will look into this as a submission.  Thanks for the reminder ;-)

Thanks :) I think the 'rift' started because Pete initially -1'ed the
creation of Commons, due to scope overlap with Avalon's charter. Here is
the posting to general@jakarta:

http://www.mail-archive.com/general%40jakarta.apache.org/msg00645.html

Since then, Commons has been a great success. But there WAS scope
overlap, as evidenced by the amount of generic utility code lying around
in Avalon.

So we have this situation where each project semi-ignores the other.
This is mostly to Avalon's detriment: many Avalon developers are on the
commons-dev list, but I suspect most Commons developers aren't on the
avalon-dev list.

So the most obvious remedy would be for Avalon to move all generic code
to Commons. This would involve:
  o Identifying what's generic (a lot of the stuff in Excalibur is
	generic, with a Component wrapper), and moving it.
  o Add required commons-*.jar to Avalon's tools/lib dir.
  o Deprecate now-obsolete Avalon code (for a looong time).

This has parallels with how Cocoon recently moved a bunch of reusable
code into Avalon.

I truly don't understand all the implications (both technical, and
issues of project identity and cohesion) of such a change.

What do Avalon people think? Worth attempting?

--Jeff

> Cheers,
> Scott Sanders
> 
> > -----Original Message-----
> > From: Jeff Turner [mailto:jeff@socialchange.net.au] 
> > Sent: Thursday, December 06, 2001 4:26 PM
> > To: Jakarta Commons Developers List
> > Subject: Re: The spirit of sharing
> > 
> > 
> > Hi,
> > 
> > I developed a pretty comprehensive class for this sort of IO stream
> > manipulation:
> > 
> > http://jakarta.apache.org/avalon/excalibur/api/org/apache/aval
> > on/excalibur/io/IOUtil.html
> > 
> > Offered to Commons as a StreamUtils replacement once, but got 
> > no reply. So I'll offer again.
> > 
> > 
> > --Jeff
> > 
> > On Thu, Dec 06, 2001 at 04:08:36PM -0800, Michael Bayne 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:
[..]

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The spirit of sharing

Posted by Jeff Turner <je...@socialchange.net.au>.
Hi,

I developed a pretty comprehensive class for this sort of IO stream
manipulation:

http://jakarta.apache.org/avalon/excalibur/api/org/apache/avalon/excalibur/io/IOUtil.html

Offered to Commons as a StreamUtils replacement once, but got no reply.
So I'll offer again.


--Jeff

On Thu, Dec 06, 2001 at 04:08:36PM -0800, Michael Bayne 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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: The spirit of sharing

Posted by Scott Sanders <sa...@totalsync.com>.
Comitted.  Thanks.

> -----Original Message-----
> From: Michael Bayne [mailto:mdb@bering] On Behalf Of Michael Bayne
> Sent: Thursday, December 06, 2001 5:09 PM
> To: commons-dev@jakarta.apache.org
> Subject: Re: The spirit of sharing
> 
> 
> On Thu, 6 Dec 2001, Michael Bayne wrote:
> 
> > +    public static byte[] streamAsBytes(InputStream toRead, 
> int bufferSize,
> > +                                       String encoding)
> 
> Whoops. Minor patch to that patch. The above lines should be:
> 
> +    public static byte[] streamAsBytes(InputStream toRead, int 
> + bufferSize)
> 
> -- mdb /o)\ "Be careful what you wish for. You won't get it,
>        \(o/  but it never hurts to be careful."
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:commons-dev-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The spirit of sharing

Posted by Michael Bayne <md...@samskivert.com>.
On Thu, 6 Dec 2001, Michael Bayne wrote:

> +    public static byte[] streamAsBytes(InputStream toRead, int bufferSize,
> +                                       String encoding)

Whoops. Minor patch to that patch. The above lines should be:

+    public static byte[] streamAsBytes(InputStream toRead, int bufferSize)

-- mdb /o)\ "Be careful what you wish for. You won't get it,
       \(o/  but it never hurts to be careful."


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The spirit of sharing

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
That's a great way :)

+1


On 12/6/01 7:08 PM, "Michael Bayne" <md...@samskivert.com> 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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.     geirm@optonline.net
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>