commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <flame...@gmail.com>
Subject Re: [io][net] Looking for a home for some util code.
Date Tue, 12 Apr 2011 21:49:24 GMT
Definitely something I found myself needing in 2003:

https://code.google.com/p/osjava/source/browse/trunk/genjava/gj-core/src/java/com/generationjava/net/UrlW.java

Hen

On Tue, Apr 12, 2011 at 12:04 PM, 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


Mime
View raw message