commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: [io][net] Looking for a home for some util code.
Date Wed, 13 Apr 2011 05:24:22 GMT
On Tue, Apr 12, 2011 at 6:47 PM, Stephen Colebourne <scolebourne@joda.org>wrote:

> Basic work with URL and URI is [io]
> Stephen
>
>
Ahh... home sweet home.
It is in SVN for [io] in IOUtils with similar methods.

Gary

On 12 April 2011 20:04, Gary Gregory <garydgregory@gmail.com> wrote:
> > Hi All:
> >
> > I am looking for a home for the code below. It seems to fit nicely in
> [io]
> > IOUtils because it reuses IOUtils. Because it is about URLs and URI it
> feels
> > like it should be in [net] perhaps.
> >
> > Thoughts?
> >
> > import java.io.IOException;
> > import java.io.InputStream;
> > import java.net.URL;
> >
> > import org.apache.commons.io.IOUtils;
> >
> > /**
> >  * URI utilities. TODO: Propose to Apache Commons IO or NET.
> > */
> > public class URLUtils {
> >
> >    /**
> >     * Gets the contents of the URL resource.
> >     *
> >     * @param url
> >     *            The URL source.
> >     * @param charset
> >     *            The charset for the URL contents.
> >     * @return The contents of the URL as a String.
> >     * @throws IOException
> >     */
> >    public static String getContentsByURL(URL url, String charset) throws
> > IOException {
> >        InputStream inputStream = url.openStream();
> >        try {
> >            return IOUtils.toString(inputStream, charset);
> >        } finally {
> >            inputStream.close();
> >        }
> >    }
> >
> > }
> > ==
> > /**
> >  * URI utilities. TODO: Propose to Apache Commons IO or NET.
> > */
> > public class URIUtils {
> >
> >    /**
> >     * Gets the contents of the URI resource.
> >     *
> >     * @param uriString
> >     *            The URI source.
> >     * @param charset
> >     *            The charset for the URI contents.
> >     * @return The contents of the URI as a String.
> >     * @throws URISyntaxException
> >     * @throws MalformedURLException
> >     * @throws IOException
> >     */
> >    public static String getContentsByURI(String uriString, String
> charset)
> > throws URISyntaxException, MalformedURLException, IOException {
> >        return URIUtils.getContentsByURI(new URI(uriString), charset);
> >    }
> >
> >    /**
> >     * Gets the contents of the URI resource.
> >     *
> >     * @param uri
> >     *            The URI source.
> >     * @param charset
> >     *            The charset for the URI contents.
> >     * @return The contents of the URI as a String.
> >     * @throws MalformedURLException
> >     * @throws IOException
> >     */
> >    public static String getContentsByURI(URI uri, String charset) throws
> > MalformedURLException, IOException {
> >        return URLUtils.getContentsByURL(uri.toURL(), charset);
> >    }
> >
> > }
> > --
> > Thank you,
> > Gary
> >
> > http://garygregory.wordpress.com/
> > http://garygregory.com/
> > http://people.apache.org/~ggregory/
> > http://twitter.com/GaryGregory
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
Thank you,
Gary

http://garygregory.wordpress.com/
http://garygregory.com/
http://people.apache.org/~ggregory/
http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message