Lecture du contenu du site Web dans une chaîne

Actuellement, je suis en train de travailler sur une classe qui peut être utilisé pour lire le contenu du site web spécifié par l'url. Je suis juste au début de mes aventures avec java.io et java.net j'ai donc besoin de consulter mon design.

Utilisation:

TextURL url = new TextURL(urlString);
String contents = url.read();

Mon code:

package pl.maciejziarko.util;

import java.io.*;
import java.net.*;

public final class TextURL
{
    private static final int BUFFER_SIZE = 1024 * 10;
    private static final int ZERO = 0;
    private final byte[] dataBuffer = new byte[BUFFER_SIZE];
    private final URL urlObject;

    public TextURL(String urlString) throws MalformedURLException
    {
        this.urlObject = new URL(urlString);
    }

    public String read() 
    {
        final StringBuilder sb = new StringBuilder();

        try
        {
            final BufferedInputStream in =
                    new BufferedInputStream(urlObject.openStream());

            int bytesRead = ZERO;

            while ((bytesRead = in.read(dataBuffer, ZERO, BUFFER_SIZE)) >= ZERO)
            {
                sb.append(new String(dataBuffer, ZERO, bytesRead));
            }
        }
        catch (UnknownHostException e)
        {
            return null;
        }
        catch (IOException e)
        {
            return null;
        }

        return sb.toString();
    }

    //Usage:
    public static void main(String[] args)
    {
        try
        {
            TextURL url = new TextURL("http://www.flickr.com/explore/interesting/7days/");
            String contents = url.read();

            if (contents != null)
                System.out.println(contents);
            else
                System.out.println("ERROR!");
        }
        catch (MalformedURLException e)
        {
            System.out.println("Check you the url!");
        }
    }
}

Ma question est:
Est-ce un bon moyen pour obtenir ce que je veux? Sont-il de meilleures solutions?

Je n'ai pas comme sb.append(new String(dataBuffer, ZERO, bytesRead)); mais je n'étais pas capable de l'exprimer d'une manière différente. Est-il bon de créer une nouvelle Chaîne à chaque itération? Je suppose que non.

Tout autre point faible?

Merci d'avance!

source d'informationauteur Maciej Ziarko