List of usage examples for java.net URL openStream
public final InputStream openStream() throws java.io.IOException
From source file:main.java.refinement_class.Useful.java
public static KieSession build(String s1, String s2) throws Exception { KieServices kieServices = KieServices.Factory.get(); kieServices.newKieClasspathContainer(H2mserviceImpl.class.getClassLoader()); KieFileSystem kfs = kieServices.newKieFileSystem(); Thread.currentThread().setContextClassLoader(H2mserviceImpl.class.getClassLoader()); try {//from w ww . j a v a 2 s . c o m URL url = getUrl(H2mserviceImpl.class, s1); kfs.write(s2, kieServices.getResources().newInputStreamResource(url.openStream())); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll(); Results results = kieBuilder.getResults(); if (results.hasMessages(Message.Level.ERROR)) { System.out.println(results.getMessages()); throw new IllegalStateException("### errors ###"); } KieContainer kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId()); KieBase kieBase = kieContainer.getKieBase(); KieSession ksession = kieContainer.newKieSession(); return ksession; }
From source file:com.vmware.appfactory.taskqueue.tasks.state.tasks.FeedScanTask.java
/** * Read the feed at the specified URL and update this feed to match. * This will change some feed attributes (most notably the applications) but * anything set by the user will remain untouched. *//*w ww .jav a 2 s. c om*/ private static Feed readFromUrl(URL url) throws IOException, FeedJsonFormatException { /* Open the feed URL. */ InputStream is = url.openStream(); Feed feed; try { feed = FeedJsonParser.readStream(is); } finally { if (null != is) { is.close(); } } feed.setUrl(url); return feed; }
From source file:io.fabric8.camel.tooling.util.CamelNamespaces.java
public static Set<String> elementsWithDescription() { if (elementsWithDescription == null) { String file = "camelDescriptionElements.txt"; String text = ""; URL url = findResource(file, null); if (url != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { FileCopyUtils.copy(url.openStream(), baos); text = new String(baos.toByteArray(), "UTF-8"); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); }//from w w w. j a v a 2s .c om } else { LOG.warn("Could not find file {} on the class path", file); } text += " camelContext"; String[] arr = text.split(" "); elementsWithDescription = new HashSet<String>(Arrays.asList(arr)); } return elementsWithDescription; }
From source file:menusearch.json.JSONProcessor.java
/** * /*from w w w.j av a 2 s . co m*/ * @param query -- formatted HTML that's used with the searchRecipes API on yummly * @return a string in JSON format that contains all the recipes that match the search parameters. * @throws MalformedURLException * @throws IOException * * You CAN NOT call this method directly -- to search Yummly call the method queryBuilder and pass it your search parameters. */ private static String searchYummly(String query) throws MalformedURLException, IOException { BufferedReader reader = null; try { URL url = new URL(query); reader = new BufferedReader(new InputStreamReader(url.openStream())); StringBuffer buffer = new StringBuffer(); int read; char[] chars = new char[1024]; while ((read = reader.read(chars)) != -1) buffer.append(chars, 0, read); return buffer.toString(); } finally { if (reader != null) reader.close(); } }
From source file:com.thruzero.common.core.utils.XmlUtils.java
public static Document createDocument(final DocumentBuilder parser, final URL sourceURL) throws IOException, SAXException { Document result = null;//from w ww . j a va2 s . c o m InputStream inStream = null; try { inStream = sourceURL.openStream(); result = createDocument(parser, inStream); xmlUtilsLogHelper.logDocumentCreated(result); } catch (IOException e) { logger.error("*** IOException: " + e); throw e; } finally { if (inStream != null) { try { inStream.close(); } catch (IOException e) { // ignore close error. } } } return result; }
From source file:fr.shywim.antoinedaniel.utils.Utils.java
/** * Download a file from the CDN server./*from w w w . ja va 2 s .c o m*/ * (Note to self: all last three params could be determined by {@link java.io.File#getPath}) * @param context Any context. * @param dst Local {@link java.io.File} to save. * @param fileName Name of the distant file to download. * @param folder Folder of the distant file to download. * @param ext Extension of the distant file to download. * @return true if file has been successfully downloaded, false in any other case. */ public static boolean downloadFileFromCdn(Context context, File dst, String fileName, String folder, String ext, boolean force) throws IOException { int count; InputStream input; FileOutputStream output; final String cdnLink = context.getResources().getString(R.string.cdn_link); if (force || !dst.exists()) { if (force || dst.createNewFile()) { URL url = new URL(cdnLink + folder + fileName + ext); input = new BufferedInputStream(url.openStream(), 4096); byte data[] = new byte[2048]; output = new FileOutputStream(dst); while ((count = input.read(data)) != -1) { output.write(data, 0, count); } output.flush(); input.close(); output.close(); } else { return false; } } return true; }
From source file:com.ms.commons.test.classloader.IntlTestURLClassPath.java
private static CopiedJDK5Manifest findSurefireBooterManifest() throws Exception { ArrayList<URL> urls = CollectionUtil.toCollection(ArrayList.class, IntlTestURLClassPath.class.getClassLoader().getResources("META-INF/MANIFEST.MF")); for (URL u : urls) { CopiedJDK5Manifest mf = new CopiedJDK5Manifest(); mf.read(u.openStream()); if ("org.apache.maven.surefire.booter.SurefireBooter" .equals(mf.getMainAttributes().getValue("Main-Class"))) { return mf; }//from w ww . j a va 2 s .com } return null; }
From source file:eu.geopaparazzi.library.network.NetworkUtilities.java
public static String readUrl(String urlString) throws Exception { URL url = new URL(urlString); InputStream inputStream = url.openStream(); BufferedReader bi = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder sb = new StringBuilder(); String line = null;/*from w w w . ja v a 2 s. c om*/ while ((line = bi.readLine()) != null) { sb.append(line).append("\n"); } inputStream.close(); return sb.toString().trim(); }
From source file:com.github.e2point718.har2jmx.HAR.java
public static String read(URL source) throws IOException { String line = null;/*from ww w. j a v a2s. c o m*/ StringBuilder bu = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(source.openStream())); try { while ((line = reader.readLine()) != null) { bu.append(line); } } finally { reader.close(); } return bu.toString(); }
From source file:br.org.acessobrasil.nucleuSilva.util.PegarPaginaWEB.java
/** * Mtodo que extrai o contedo de uma pgina. * //from w w w .j av a 2 s. co m * @param url * URL da pgina a ter seu contedo extrado. * @return Contedo de uma pgina. * @throws IOException * Erro ao conectar a pgina. * @deprecated Utilize o mtodo getContent(). */ public static StringBuilder pegar(final URL url) throws IOException { StringBuilder buf = new StringBuilder(); InputStreamReader isr = new InputStreamReader(url.openStream()); BufferedReader in = new BufferedReader(isr); while (in.ready()) { buf.append(in.readLine() + "\n"); } in.close(); // aqui simplesmente lido uma pagina da internet e retornada em buf, // sem tratamentos return buf; }