List of usage examples for java.net URLConnection getInputStream
public InputStream getInputStream() throws IOException
From source file:plugins.marauders.MaraudersInteractor.java
public static Data getData() { StringBuilder json = new StringBuilder(); try {/* ww w. j av a 2 s. co m*/ URL server = new URL("http://s40server.csse.rose-hulman.edu:9200/marauders/data/0"); URLConnection yc = server.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null && inputLine != "") { System.out.println(inputLine); json.append(inputLine); } in.close(); } catch (Exception e) { e.printStackTrace(); } ObjectMapper mapper = new ObjectMapper(); TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() { }; try { HashMap<String, Object> map = mapper.readValue(json.toString(), typeReference); HashMap<String, Object> source = (HashMap) map.get("_source"); Data d = new Data(); d.setLastStudentID(Integer.parseInt((String) source.get("lastStudentID"))); d.setMaxInsultID(Integer.parseInt((String) source.get("maxInsultID"))); d.setPassphrase((String) source.get("passphrase")); return d; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:com.flexdesktop.connections.restfulConnection.java
public static ArrayList<ArrayList<String>> getRESTful(String RESTfull_URL, ArrayList<String> columnasTabla) { try {/* w w w . j a v a2s .c o m*/ URL url; URLConnection urlConnection; DataInputStream readString; url = new URL(RESTfull_URL); urlConnection = url.openConnection(); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); readString = new DataInputStream(urlConnection.getInputStream()); String s; String getRequest = ""; while ((s = readString.readLine()) != null) { getRequest += s; } readString.close(); if (!"".equals(getRequest)) { return completeArray(getRequest, columnasTabla); } } catch (Exception ex) { Logger.getLogger(com.flexdesktop.connections.restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:dataflow.feed.api.Weather.java
/** * Method which builds the string of the URL to call * @param myURL the URL which must become a callURL * @return /*from w ww. j a v a 2 s .c o m*/ */ public static String callURL(String myURL) { //System.out.println("Requested URL:" + myURL); StringBuilder sb = new StringBuilder(); URLConnection urlConn = null; InputStreamReader in = null; try { URL url = new URL(myURL); urlConn = url.openConnection(); if (urlConn != null) urlConn.setReadTimeout(60 * 1000); if (urlConn != null && urlConn.getInputStream() != null) { in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); BufferedReader bufferedReader = new BufferedReader(in); if (bufferedReader != null) { int cp; while ((cp = bufferedReader.read()) != -1) { sb.append((char) cp); } bufferedReader.close(); } } in.close(); } catch (Exception e) { throw new RuntimeException("Exception while calling URL:" + myURL, e); } return sb.toString(); }
From source file:fr.free.movierenamer.utils.URIRequest.java
private static InputStream getInputStreamNoSync(URLConnection connection) throws IOException { String encoding = connection.getContentEncoding(); InputStream inputStream;//from www . j a va 2 s . c om try { inputStream = connection.getInputStream(); } catch (IOException ioe) { throw ioe; } if ("gzip".equalsIgnoreCase(encoding)) { inputStream = new GZIPInputStream(inputStream); } else if ("deflate".equalsIgnoreCase(encoding)) { inputStream = new InflaterInputStream(inputStream, new Inflater(true)); } return inputStream; }
From source file:flexpos.restfulConnection.java
public static ArrayList<ArrayList<String>> getRESTful(String RESTfull_URL, ArrayList<String> columnasTabla) { try {//from w w w .j a v a2 s . co m URL url; URLConnection urlConnection; DataInputStream readString; url = new URL(RESTfull_URL); urlConnection = url.openConnection(); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); readString = new DataInputStream(urlConnection.getInputStream()); String s; String getRequest = ""; while ((s = readString.readLine()) != null) { getRequest += s; } readString.close(); if (!"".equals(getRequest)) { return completeArray(getRequest, columnasTabla); } } catch (Exception ex) { Logger.getLogger(restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.fluidops.iwb.cms.util.OpenUp.java
public static List<Statement> extract(String text, URI uri) throws IOException { List<Statement> res = new ArrayList<Statement>(); String textEncoded = URLEncoder.encode(text, "UTF-8"); String send = "format=rdfxml&text=" + textEncoded; // service limit is 10000 chars if (mode() == Mode.demo) send = stripToDemoLimit(send);//from w ww . j a v a 2s . c o m // GET only works for smaller texts // URL url = new URL("http://openup.tso.co.uk/des/enriched-text?text=" + textEncoded + "&format=rdfxml"); URL url = new URL(getConfig().getOpenUpUrl()); URLConnection conn = url.openConnection(); conn.setDoOutput(true); IOUtils.write(send, conn.getOutputStream()); Repository repository = new SailRepository(new MemoryStore()); try { repository.initialize(); RepositoryConnection con = repository.getConnection(); con.add(conn.getInputStream(), uri.stringValue(), RDFFormat.RDFXML); RepositoryResult<Statement> iter = con.getStatements(null, null, null, false); while (iter.hasNext()) { Statement s = iter.next(); res.add(s); } } catch (Exception e) { throw new RuntimeException(e); } return res; }
From source file:com.buglabs.dragonfly.util.WSHelper.java
protected static InputStream getAsStream(URL url) throws IOException { URLConnection conn = url.openConnection(); conn.setDoInput(true);//from w w w . j a v a2 s.c om conn.setDoOutput(false); return conn.getInputStream(); }
From source file:at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl.java
private static void loadXAdES14Blacklist() { XADES_1_4_BLACKLIST_TS = System.currentTimeMillis(); XADES_1_4_BLACKLIST.clear();/*w w w . j a v a 2 s. com*/ try { URLConnection blc = new URL(ConfigurationFacade.XADES_1_4_BLACKLIST_URL).openConnection(); blc.setUseCaches(false); InputStream in = blc.getInputStream(); Scanner s = new Scanner(in); while (s.hasNext()) { XADES_1_4_BLACKLIST.add(s.next()); } s.close(); } catch (Exception e) { log.error("Blacklist load error", e); } }
From source file:eionet.cr.util.xml.ConversionsParser.java
/** * * @param schemaUri//w w w .j a v a 2 s .co m * @return * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ public static ConversionsParser parseForSchema(String schemaUri) throws IOException, SAXException, ParserConfigurationException { String listConversionsUrl = GeneralConfig.getRequiredProperty(GeneralConfig.XMLCONV_LIST_CONVERSIONS_URL); listConversionsUrl = MessageFormat.format(listConversionsUrl, Util.toArray(URLEncoder.encode(schemaUri))); URL url = new URL(listConversionsUrl); URLConnection urlConnection = url.openConnection(); InputStream inputStream = null; try { // avoid keep-alive by setting "Connection: close" header urlConnection.setRequestProperty("Connection", "close"); inputStream = urlConnection.getInputStream(); ConversionsParser conversionsParser = new ConversionsParser(); conversionsParser.parse(inputStream); return conversionsParser; } finally { IOUtils.closeQuietly(inputStream); URLUtil.disconnect(urlConnection); } }
From source file:de.feanor.yeoldemensa.data.MensaFactory.java
/** * Returns an input stream for the given path on the server defined by * MensaFactory.SERVER_URL. Checks for a valid internet connection before * conneting.//from ww w .ja v a 2s . c o m * * @param path * Path on the server/URL * @param context * Application context, required for connection check * @return Inputstream for the given path * @throws IOException * Thrown if problems with the connection occur */ private static InputStream getInputStream(String path) throws IOException { URLConnection conn = new URL(SERVER_URL + path).openConnection(); conn.setConnectTimeout(TIMEOUT * 1000); conn.setReadTimeout(TIMEOUT * 1000); return conn.getInputStream(); }