Java URL Read readURL(URLConnection connection, String charset)

Here you can find the source of readURL(URLConnection connection, String charset)

Description

read URL

License

Open Source License

Declaration

public static String readURL(URLConnection connection, String charset) throws IOException 

Method Source Code

//package com.java2s;
/**// ww  w .j a v  a2s. c o  m
 * aTunes 1.6.0
 * Copyright (C) 2006-2007 Alex Aranda (fleax) alex.aranda@gmail.com
 *
 * http://www.atunes.org
 * http://sourceforge.net/projects/atunes
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

import java.io.IOException;
import java.io.InputStream;

import java.net.URLConnection;

public class Main {
    public static String readURL(URLConnection connection) throws IOException {
        StringBuilder builder = new StringBuilder();
        InputStream input = connection.getInputStream();
        byte[] array = new byte[1024];
        int read;
        while ((read = input.read(array)) > 0) {
            builder.append(new String(array, 0, read, "UTF-8"));
        }
        return builder.toString();
    }

    public static String readURL(URLConnection connection, String charset) throws IOException {
        StringBuilder builder = new StringBuilder();
        InputStream input = connection.getInputStream();
        byte[] array = new byte[1024];
        int read;
        while ((read = input.read(array)) > 0) {
            builder.append(new String(array, 0, read, charset));
        }
        return builder.toString();
    }
}

Related

  1. readUrl(String url_str)
  2. readUrl(String urlString)
  3. readURL(URL url)
  4. readUrl(URL url)
  5. readUrl(URL url, String[]... headers)
  6. readUrlContent(URLConnection connection)
  7. readURLToString(String url)
  8. readUrlToString(String urlString)
  9. readVersion(URLConnection connection)