You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2011/04/12 21:04:20 UTC

[io][net] Looking for a home for some util code.

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

Re: [io][net] Looking for a home for some util code.

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Apr 12, 2011 at 6:47 PM, Stephen Colebourne <sc...@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 <ga...@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

Re: [io][net] Looking for a home for some util code.

Posted by Stephen Colebourne <sc...@joda.org>.
Basic work with URL and URI is [io]
Stephen

On 12 April 2011 20:04, Gary Gregory <ga...@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


Re: [io][net] Looking for a home for some util code.

Posted by Henri Yandell <fl...@gmail.com>.
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 <ga...@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


Re: [io][net] Looking for a home for some util code.

Posted by sebb <se...@gmail.com>.
On 12 April 2011 20:04, Gary Gregory <ga...@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.

IMO Net is more about protocols, rather than utilities such as this,
so I think IO is a more natural home.

> 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