List of usage examples for java.io StringReader StringReader
public StringReader(String s)
From source file:Main.java
/** * Metodo para carregar uma string contendo um arquivo xml assinado. * /*w w w . j a v a 2s .c o m*/ * @param xmlString -> XML assinado. * * @return org.w3c.dom.Document * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public static Document carregarArquivoXML(String xmlString) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = null; DocumentBuilder db; db = dbf.newDocumentBuilder(); doc = db.parse(new InputSource(new StringReader(xmlString))); return doc; }
From source file:com.thoughtworks.go.security.RegistrationJSONizer.java
public static Registration fromJson(String json) { Map map = GSON.fromJson(json, Map.class); if (map.isEmpty()) { return Registration.createNullPrivateKeyEntry(); }// w w w .j a v a 2 s.c o m List<X509Certificate> chain = new ArrayList<>(); try { PemReader reader = new PemReader(new StringReader((String) map.get("agentPrivateKey"))); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(reader.readPemObject().getContent()); PrivateKey privateKey = kf.generatePrivate(spec); String agentCertificate = (String) map.get("agentCertificate"); PemReader certReader = new PemReader(new StringReader(agentCertificate)); while (true) { PemObject obj = certReader.readPemObject(); if (obj == null) { break; } chain.add((X509Certificate) CertificateFactory.getInstance("X.509") .generateCertificate(new ByteArrayInputStream(obj.getContent()))); } return new Registration(privateKey, chain.toArray(new X509Certificate[0])); } catch (IOException | NoSuchAlgorithmException | CertificateException | InvalidKeySpecException e) { throw bomb(e); } }
From source file:Main.java
public static Document toXMLDocument(String xmlString) { return toXMLDocument(new InputSource(new StringReader(xmlString))); }
From source file:co.runrightfast.core.utils.JsonUtils.java
static javax.json.JsonObject parse(final String json) { checkArgument(isNotBlank(json));/* www . j a v a 2 s .c o m*/ try (final JsonReader reader = Json.createReader(new StringReader(json))) { return reader.readObject(); } }
From source file:Main.java
/** * Marshal a object of/* www . j a va 2s . c o m*/ * <code>classItem</code> from the xmlResponse * <code>String</code>. * * @param xmlResponse <code>String</code> that represents the object to be * marshal. * @param classItem <code>String</code> of the returns object. * @return a object of <code>classItem</code>. * @throws JAXBException throw trying to marshal. */ public static Object unmarshalFromString(String xmlResponse, String classItem) throws JAXBException { final JAXBContext jaxbContext = JAXBContext.newInstance(classItem); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); StringReader reader = null; try { reader = new StringReader(xmlResponse); return jaxbUnmarshaller.unmarshal(reader); } finally { if (reader != null) reader.close(); } }
From source file:Main.java
/** * Example for retrieving the APAS institutions list * * @param xml the string representation of the XML * * @return the Document object created from the XML string representation * * @throws IOException if an I/O error occurs * @throws SAXException if an XML parsing exception occurs. * @throws ParserConfigurationException if a JAXP configuration error * occurs. *///www . j a v a 2s . c om public static Document stringToDocument(final String xml) throws SAXException, IOException, ParserConfigurationException { return loadXMLFrom(new InputSource(new StringReader(xml))); }
From source file:Main.java
private static DocumentBuilder getBuilder() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);//from w w w . jav a2 s. c om factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder builder = factory.newDocumentBuilder(); // prevent DTD entities from being resolved. builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); return builder; }
From source file:Main.java
/** * This method will validate a non-niem xml instance. * //from www.j av a2 s .c om * @param xsdPath - this is a relative path to an xsd, typically in OJB_Utilies or in the enclosing project * @param xml - This is the XML document as a string * @throws Exception - typically a validation exception or a file path exception */ public static void validateInstanceNonNIEMXsd(String xsdPath, String xml) throws Exception { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(new File(xsdPath)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(new StringReader(xml))); }
From source file:Main.java
/** * Apply the XSLT transformation (<code>xslt</code>) to the XML given ( * <code>inputXmlStream</code>) and write the output to * <code>outputStream</code> * /*w w w. j av a2 s . c o m*/ * @param xslt * @param xsltParameters * @param inputXmlStream * @param outputStream * * @return the {@link OutputStream} with the transformation output. * * @throws TransformerException */ public static OutputStream applyTransformation(String xslt, Map<String, Object> xsltParameters, InputStream inputXmlStream, OutputStream outputStream) throws TransformerException { return applyTransformation(new StreamSource(new StringReader(xslt)), xsltParameters, inputXmlStream, outputStream); }
From source file:dk.dma.msinm.user.security.Credentials.java
/** * Attempts to parse the request JSON payload as Credentials, and returns null if it fails * @param requestBody the request/* www . jav a 2 s .com*/ * @return the parsed credentials or null */ public static Credentials fromRequest(String requestBody) { Credentials credentials = new Credentials(); try (JsonReader jsonReader = Json.createReader(new StringReader(requestBody))) { JsonObject jsonObject = jsonReader.readObject(); credentials.setEmail(jsonObject.getString("email")); credentials.setPassword(jsonObject.getString("password")); } catch (Exception e) { // No valid credentials } return (credentials.isValid()) ? credentials : null; }