List of usage examples for java.net URL openStream
public final InputStream openStream() throws java.io.IOException
From source file:Main.java
/** * The method read a XML from URL, skips irrelevant chars and serves back the content as string. * @param inputStream/*from w w w. j a va 2 s . c om*/ * @return String : content of a file * @throws IOException */ public static String getURLToString(URL url) throws IOException { InputStreamReader inputStream = new InputStreamReader(url.openStream(), "ISO-8859-1"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { int i = inputStream.read(); while (i != -1) { if (i != TAB && i != NL && i != CR) byteArrayOutputStream.write(i); i = inputStream.read(); } String x = byteArrayOutputStream.toString("UTF-8"); return x; } catch (IOException e) { e.printStackTrace(); return ""; } finally { inputStream.close(); } }
From source file:Util.java
/** * Charge une url et renvoie le contenu//from w w w . j a va 2 s . c o m * * @param url * @return le contenu de l'url ou "" si erreur */ public static String loadUrl(URL url) throws IOException { InputStream stream = null; try { stream = url.openStream(); return loadStream(stream); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } }
From source file:com.bigfatgun.fixjures.json.JSONSource.java
public static FixtureSource newRemoteUrl(final URL url) { try {//w w w . j a v a2 s . c o m return new JSONSource(url.openStream()); } catch (IOException e) { throw FixtureException.convert(e); } }
From source file:Main.java
public static Bitmap decodeUrl(URL url) { InputStream stream = null;//from ww w.j ava 2 s . c o m try { stream = url.openStream(); } catch (IOException e) { Log.w(LOGTAG, "decodeUrl: IOException downloading " + url); return null; } if (stream == null) { Log.w(LOGTAG, "decodeUrl: stream not found downloading " + url); return null; } Bitmap bitmap = decodeStream(stream); try { stream.close(); } catch (IOException e) { Log.w(LOGTAG, "decodeUrl: IOException closing stream " + url, e); } return bitmap; }
From source file:Main.java
public static Document createDocument(URL url) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(url.openStream()); }//www . j a v a2 s .c o m }
From source file:com.mycompany.semconsolewebapp.FileUpload.java
public static String getUploadURL(String reqURL) throws MalformedURLException, IOException { URL url = new URL(reqURL); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); return in.readLine(); // Will only ever return one line, so we don't need a loop }
From source file:com.khs.sherpa.util.Util.java
public static Properties getProperties(URL url) throws IOException { Properties properties = new Properties(); properties.load(url.openStream()); return properties; }
From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java
private static void writeUrlToFile(URL url, File file) throws Exception { InputStream in = url.openStream(); String str = IOUtils.toString(in, ENDODING); str = str.replaceAll("description=\".*\"", "description=\"\""); IOUtils.closeQuietly(in);/*w w w . j a v a 2 s.com*/ FileUtils.writeStringToFile(file, str, ENDODING); }
From source file:com.aestasit.markdown.Markdown.java
public static RootNode toAst(final URL url, final int options) throws IOException { return toAst(url.openStream(), options); }
From source file:org.elasticsearch.xpack.qa.sql.jdbc.DataLoader.java
@SuppressForbidden(reason = "test reads from jar") public static InputStream readFromJarUrl(URL source) throws IOException { return source.openStream(); }