Java URL Connection urlToText(@Nonnull String url)

Here you can find the source of urlToText(@Nonnull String url)

Description

Obtains content of URL to String.

License

Open Source License

Declaration

public static String urlToText(@Nonnull String url) throws Exception 

Method Source Code

//package com.java2s;
/*-/*www .  j  a v  a  2s . co m*/
 * #%L
 * org.matonto.ontology.api
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2016 iNovex Information Systems, Inc.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 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.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

import javax.annotation.Nonnull;

public class Main {
    /**
     * Obtains content of URL to String.
     */
    public static String urlToText(@Nonnull String url) throws Exception {
        URL website = new URL(url);
        URLConnection connection = website.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));

        StringBuilder response = new StringBuilder();
        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine + "\n");
        }
        in.close();

        return response.toString();
    }
}

Related

  1. URLExists(URL url, StringBuffer errorMsg)
  2. urlifyMap(Long nid, double latitude, double longitude)
  3. urlToHtm(String word, String findurl, String path)
  4. urlToReader(URL url)
  5. urlToString(String url)