List of usage examples for java.net URL openStream
public final InputStream openStream() throws java.io.IOException
From source file:org.smartdeveloperhub.vocabulary.config.ConfigurationFactory.java
static <T extends Configuration> T load(final URL url, final Class<? extends T> clazz) throws IOException { final ObjectMapper mapper = parsingMapper(); try (InputStream openStream = url.openStream()) { return mapper.readValue(openStream, clazz); }/* www .j ava 2 s .c o m*/ }
From source file:br.net.fabiozumbi12.RedProtect.hooks.MojangUUIDs.java
public static String getUUID(String player) { try {/*from w w w. ja v a 2s . c o m*/ URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + player); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line = in.readLine(); if (line == null) { return null; } JSONObject jsonProfile = (JSONObject) new JSONParser().parse(line); String name = (String) jsonProfile.get("id"); return toUUID(name); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:com.cardFetcher.Fetcher.JSONFetcher.java
public static JSONArray getJSON() { BufferedReader reader = null; URL url = null; String output = ""; try {/* w w w .j a va 2 s.com*/ url = new URL("http://www.netrunnerdb.com/api/cards/"); reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); output = reader.readLine(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (reader != null) reader.close(); } catch (Exception e) { e.printStackTrace(); } } return new JSONArray(output); }
From source file:com.geewhiz.pacify.utils.FileUtils.java
public static List<String> getFileAsLines(URL fileURL, String encoding) { InputStream is = null;/*ww w . jav a2s . c om*/ try { is = fileURL.openStream(); return IOUtils.readLines(is, Charsets.toCharset(encoding)); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } }
From source file:org.opendaylight.atrium.hostservice.impl.ConfigReader.java
public static boolean initialize(URL configFileUrl) { byte[] jsonData = null; if (configFileUrl != null) { try {// w w w . j a v a 2 s. c om InputStream input = configFileUrl.openStream(); jsonData = IOUtils.toByteArray(input); input.close(); } catch (IOException e) { e.printStackTrace(); } } ObjectMapper objectMapper = new ObjectMapper(); try { rootJsonNode = objectMapper.readTree(jsonData); } catch (IOException e) { return false; } return true; }
From source file:org.wso2.carbon.apimgt.impl.utils.CommonUtil.java
public static void validateWsdl(String url) throws APIManagementException, IOException { BufferedReader in = null;/*from w w w. ja va 2 s . c om*/ try { URL wsdl = new URL(url); in = new BufferedReader(new InputStreamReader(wsdl.openStream())); String inputLine; boolean isWsdl2 = false; boolean isWsdl10 = false; StringBuilder urlContent = new StringBuilder(); while ((inputLine = in.readLine()) != null) { String wsdl2NameSpace = "http://www.w3.org/ns/wsdl"; String wsdl10NameSpace = "http://schemas.xmlsoap.org/wsdl/"; urlContent.append(inputLine); isWsdl2 = urlContent.indexOf(wsdl2NameSpace) > 0; isWsdl10 = urlContent.indexOf(wsdl10NameSpace) > 0; } if (isWsdl10) { javax.wsdl.xml.WSDLReader wsdlReader11 = null; try { wsdlReader11 = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader(); wsdlReader11.readWSDL(url); } catch (WSDLException e) { handleException("Unable to process wsdl 1.0", e); } } else if (isWsdl2) { WSDLReader wsdlReader20 = null; try { wsdlReader20 = WSDLFactory.newInstance().newWSDLReader(); wsdlReader20.readWSDL(url); } catch (org.apache.woden.WSDLException e) { handleException("Unable to process wsdl 2.0", e); } } else { handleException("URL is not in format of wsdl1/wsdl2"); } } finally { in.close(); } }
From source file:edu.wustl.cab2b.common.authentication.GTSSynchronizer.java
/** * This method generates the globus certificate in user.home folder * @param gridType/*from w w w. j av a 2s .co m*/ */ public static void generateGlobusCertificate() { URL signingPolicy = Utility.class.getClassLoader().getResource(CagridPropertyLoader.getSigningPolicy()); URL certificate = Utility.class.getClassLoader().getResource(CagridPropertyLoader.getCertificate()); if (signingPolicy != null || certificate != null) { copyCACertificates(signingPolicy); copyCACertificates(certificate); } else { logger.error("Could not find CA certificates"); throw new AuthenticationException("Could not find CA certificates.", ErrorCodeConstants.CDS_016); } logger.debug("Getting sync-descriptor.xml file"); try { logger.debug("Synchronizing with GTS service"); URL syncDescFile = Utility.class.getClassLoader().getResource(CagridPropertyLoader.getSyncDesFile()); Document doc = XMLUtils.newDocument(syncDescFile.openStream()); Object obj = ObjectDeserializer.toObject(doc.getDocumentElement(), SyncDescription.class); SyncDescription description = (SyncDescription) obj; SyncGTS.getInstance().syncOnce(description); logger.debug("Successfully syncronized with GTS service. Globus certificates generated."); } catch (Exception e) { logger.error(e.getMessage(), e); throw new AuthenticationException( "Error occurred while generating globus certificates: " + e.getMessage(), e, ErrorCodeConstants.CDS_004); } }
From source file:com.linkedin.pinot.core.realtime.impl.kafka.KafkaAvroMessageDecoder.java
public static org.apache.avro.Schema fetchSchema(URL url) throws Exception { BufferedReader reader = null; reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); StringBuilder queryResp = new StringBuilder(); for (String respLine; (respLine = reader.readLine()) != null;) { queryResp.append(respLine);/* ww w . j a va2 s. c o m*/ } return org.apache.avro.Schema.parse(queryResp.toString()); }
From source file:Main.java
public static String readTextFile(URL url) throws IOException { if (url == null) return ""; BufferedInputStream bis = null; StringBuffer sb = new StringBuffer(); try {// w ww . j av a 2 s . c o m bis = new BufferedInputStream(url.openStream()); byte buff[] = new byte[2048]; int bytesRead; while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) sb.append(new String(buff, 0, bytesRead)); } catch (IOException e) { throw e; } return sb.toString(); }
From source file:com.easarrive.aws.plugins.common.util.SNSUtil.java
public static boolean isMessageSignatureValid(SNSMessage msg) { try {/* w ww .ja v a 2s . c om*/ URL url = new URL(msg.getSigningCertURL()); InputStream inStream = url.openStream(); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream); inStream.close(); Signature sig = Signature.getInstance("SHA1withRSA"); sig.initVerify(cert.getPublicKey()); sig.update(getMessageBytesToSign(msg)); return sig.verify(Base64.decodeBase64(msg.getSignature())); } catch (Exception e) { throw new SecurityException("Verify method failed.", e); } }