Search in sources :

Example 31 with StringReader

use of java.io.StringReader in project openhab1-addons by openhab.

the class FrontierSiliconRadioApiResult method getXmlDocFromString.

/**
     * converts the string we got from the radio to a parsable XML document
     * 
     * @param xmlString
     *            the XML string read from the radio
     * @return the parsed XML document
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     */
private Document getXmlDocFromString(String xmlString) throws ParserConfigurationException, SAXException, IOException {
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = factory.newDocumentBuilder();
    final Document xmlDocument = builder.parse(new InputSource(new StringReader(xmlString)));
    return xmlDocument;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 32 with StringReader

use of java.io.StringReader in project openhab1-addons by openhab.

the class SonosXMLParser method getMetaDataFromXML.

public static SonosMetaData getMetaDataFromXML(String xml) throws SAXException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    // logger.debug("getTrackFromXML {}",xml);
    MetaDataHandler handler = new MetaDataHandler();
    reader.setContentHandler(handler);
    try {
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        logger.error("Could not parse AV Transport Event: {}", e);
    }
    return handler.getMetaData();
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 33 with StringReader

use of java.io.StringReader in project openhab1-addons by openhab.

the class SonosXMLParser method getZoneGroupFromXML.

/**
     * @param controller
     * @param xml
     * @return zone group from the given xml
     * @throws IOException
     * @throws SAXException
     */
public static List<SonosZoneGroup> getZoneGroupFromXML(String xml) throws SAXException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    ZoneGroupHandler handler = new ZoneGroupHandler();
    reader.setContentHandler(handler);
    try {
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        logger.error("Could not parse ZoneGroup from String {}", xml);
    }
    return handler.getGroups();
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 34 with StringReader

use of java.io.StringReader in project openhab1-addons by openhab.

the class SonosXMLParser method getEntriesFromString.

/**
     * @param xml
     * @return a list of Entrys from the given xml string.
     * @throws IOException
     * @throws SAXException
     */
public static List<SonosEntry> getEntriesFromString(String xml) throws SAXException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    EntryHandler handler = new EntryHandler();
    reader.setContentHandler(handler);
    try {
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        logger.error("Could not parse Entries from String {}", xml);
    }
    return handler.getArtists();
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 35 with StringReader

use of java.io.StringReader in project openhab1-addons by openhab.

the class SonosXMLParser method getAVTransportFromXML.

public static Map<String, StateVariableValue> getAVTransportFromXML(String xml) throws SAXException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    AVTransportEventHandler handler = new AVTransportEventHandler();
    reader.setContentHandler(handler);
    try {
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        logger.error("Could not parse AV Transport Event: {}", e);
    }
    return handler.getChanges();
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Aggregations

StringReader (java.io.StringReader)4150 Test (org.junit.Test)1003 IOException (java.io.IOException)589 Reader (java.io.Reader)445 InputSource (org.xml.sax.InputSource)408 BufferedReader (java.io.BufferedReader)342 TokenStream (org.apache.lucene.analysis.TokenStream)302 ArrayList (java.util.ArrayList)273 StringWriter (java.io.StringWriter)251 Tokenizer (org.apache.lucene.analysis.Tokenizer)241 Document (org.w3c.dom.Document)232 JSONReader (com.alibaba.fastjson.JSONReader)195 DocumentBuilder (javax.xml.parsers.DocumentBuilder)180 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)157 Map (java.util.Map)144 HashMap (java.util.HashMap)136 Element (org.w3c.dom.Element)134 StreamSource (javax.xml.transform.stream.StreamSource)132 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120