Example usage for java.io StringReader StringReader

List of usage examples for java.io StringReader StringReader

Introduction

In this page you can find the example usage for java.io StringReader StringReader.

Prototype

public StringReader(String s) 

Source Link

Document

Creates a new string reader.

Usage

From source file:com.dianxin.imessage.common.util.SignUtil.java

public static PrivateKey getPrivateKey(String keypath) {
    if (privateKey != null)
        return privateKey;
    log.debug("???");
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    try {/*from  w  ww. j  a  va 2 s .  c  o m*/
        FileReader fileReader = new FileReader(keypath);
        char[] cbuf = new char[40960];
        fileReader.read(cbuf, 0, 40960);
        PEMReader reader = new PEMReader(new StringReader(new String(cbuf)));
        KeyPair keyPair = (KeyPair) reader.readObject();
        privateKey = keyPair.getPrivate();
        reader.close();
    } catch (Exception e) {
        log.warn("??", e);
    }
    return privateKey;
}

From source file:Main.java

public static Document readXML(String str) throws Exception {
    if (str == null) {
        return null;
    }//  w ww .  j  a  va 2  s. co m
    Reader reader = new StringReader(str);
    return readXML(reader);
}

From source file:edu.harvard.i2b2.timeline.lifelines.QueryClient.java

public static OMElement getQueryPayLoad(String queryXML) throws XMLStreamException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://mgh.harvard.edu/i2b2", "");
    OMElement method = fac.createOMElement("queryPatient", omNs);

    StringReader strReader = new StringReader(queryXML);
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader reader = xif.createXMLStreamReader(strReader);

    StAXOMBuilder builder = new StAXOMBuilder(reader);
    OMElement lineItem = builder.getDocumentElement();
    method.addChild(lineItem);//from w  w w .  ja v  a 2 s  . com
    return method;
}

From source file:com.aurel.track.admin.customize.scripting.ScriptUtil.java

/**
 * Read the parameter script line by line
 * @param content//from   w w w .j  a va  2 s  .  c om
 * @return
 */
public static List<String> getParameterDataLines(String content) {
    List<String> lines = new ArrayList<String>();
    if (content != null) {
        BufferedReader reader = new BufferedReader(new StringReader(content));
        try {
            String line = null;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException e) {
            LOGGER.warn("Getting the line failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                LOGGER.warn("Closing the stream failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    return lines;
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.Html2Text.java

public void parse(String in) throws IOException {
    Reader r = new StringReader(in);
    try {//from   w w  w  .j a va2  s .co m
        parse(r);
    } catch (IOException e) {
        log.error("could not strip html", e);
    } finally {
        r.close();
    }
}

From source file:eu.swiec.bearballin.common.io.FileIO.java

static public String[] getLoginPassFromCSVString(String inputString) throws IOException {
    return getLoginPassFromCSV(new StringReader(inputString));
}

From source file:Main.java

public static Document newXmlDocument(String xml) {
    try {/*from  ww  w . j  a  va 2 s . co m*/
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        return docBuilder.parse(new InputSource(new StringReader(xml.toString())));
    } catch (ParserConfigurationException | SAXException | IOException ex) {
        System.err.println("Error: Canot create new XML document");
        System.err.println("Cause: " + ex.getMessage());
        System.exit(1);
        return null;
    }
}

From source file:Main.java

/** Parse a valid xml string and return the Element representing this string. */
public static Element parseXMLString(Document document, String string)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from w  ww  .  j a v a  2 s.co m
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document subDoc = builder.parse(new InputSource(new StringReader(string)));
    Element e = subDoc.getDocumentElement();
    return (Element) document.importNode(e, true);
}

From source file:Main.java

public static Document getXmlDocFromString(String xml) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);//from w  w  w  .ja  v  a  2 s  . c  o m
    dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    DocumentBuilder builder = dbf.newDocumentBuilder();
    builder.setEntityResolver(new EntityResolver() {
        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
        }
    });
    return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
}

From source file:Main.java

public static Document getDocument(String payload)
        throws ParserConfigurationException, SAXException, IOException {
    if (payload == null || payload.length() < 1)
        return null;

    StringReader sr = new StringReader(payload);
    InputSource source = new InputSource(sr);

    return getDocument(source, null);
}