Java tutorial
/////////////////////////////////////////////////////////////////////////////// //Copyright (C) 2014 Assaf Urieli // //This file is part of Jochre. // //Jochre 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. // //Jochre 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 Affero General Public License for more details. // //You should have received a copy of the GNU Affero General Public License //along with Jochre. If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////// package com.joliciel.jochre.search.webClient; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.net.URL; import java.net.URLConnection; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.joliciel.talismane.utils.LogUtils; public class SearchWebClientUtils { private static final Log LOG = LogFactory.getLog(SearchWebClientUtils.class); public static String getJson(URL url) { try { URLConnection con = url.openConnection(); InputStream in = con.getInputStream(); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String json = writer.toString(); return json; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } } }