Example usage for java.io StringReader close

List of usage examples for java.io StringReader close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes the stream and releases any system resources associated with it.

Usage

From source file:Main.java

public static void main(String[] argv) throws IOException {
    StringReader stringReader = new StringReader("java2s.com");
    System.out.println(stringReader.read());

    stringReader.close();
}

From source file:Main.java

public static void main(String[] argv) throws IOException {
    StringReader stringReader = new StringReader("java2s.com");
    stringReader.skip(2);/*  w ww  .j a  va2s. c om*/
    System.out.println(stringReader.read());

    stringReader.close();
}

From source file:Main.java

public static void main(String[] argv) throws IOException {
    StringReader stringReader = new StringReader("java2s.com");

    stringReader.mark(2);/*from   w  ww .  j  a  v a2s  .  c  om*/

    System.out.println(stringReader.markSupported());

    System.out.println(stringReader.read());

    stringReader.reset();

    stringReader.close();
}

From source file:Main.java

public static void main(String[] argv) throws IOException {
    StringReader stringReader = new StringReader("java2s.com");

    System.out.println(stringReader.ready());

    char[] charArray = new char[10];
    stringReader.read(charArray);/*from ww w .  ja v a  2 s.  c  o  m*/
    System.out.println(Arrays.toString(charArray));

    stringReader.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String xml = "<xml xmlns:log='http://sample.com'><test log:writer='someWriter'/></xml>";
    StringReader xmlReader = new StringReader(xml);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);/*ww  w. java2s .  c o  m*/
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new InputSource(xmlReader));

    Element currentNode = (Element) doc.getElementsByTagName("test").item(0);
    String attributeValue = currentNode.getAttributes().getNamedItemNS("http://sample.com", "writer")
            .getNodeValue();
    System.out.println("Attribute value is " + attributeValue);
    xmlReader.close();
}

From source file:org.apache.gobblin.util.PropertiesUtils.java

public static Properties deserialize(String serialized) throws IOException {
    StringReader reader = new StringReader(serialized);
    Properties properties = new Properties();
    properties.load(reader);/*  w  w w.  j  a v a 2s. c  om*/
    reader.close();
    return properties;
}

From source file:httputils.HttpUtil.java

public static JsonObject convertStringToJson(String jstring) {
    StringReader in = new StringReader(jstring);
    JsonReader reader = Json.createReader(in);
    JsonObject jObj = reader.readObject();
    reader.close();/* w  ww .  j a  v  a  2s  .  c  o  m*/
    in.close();

    return jObj;
}

From source file:Main.java

/**
 * Marshal a object of//from   www .j  a va2 s  .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>class</code> of the returns object.
 * @return a object of <code>classItem</code>.
 * @throws JAXBException throw trying to marshal.
 */
public static Object unmarshalFromString(String xmlResponse, Class 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

/**
 * Marshal a object of/*from  w  w  w.  j a  va 2  s. co  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:dk.netarkivet.common.utils.XmlUtils.java

/** Parses a given string to produce a {@link org.w3c.dom.Document} 
 * instance./*from   w w w . j  a  v a  2s.co m*/
 * @param xml Some XML text.
 * @return a {@link org.w3c.dom.Document} parsed from the given xml. 
 * @throws DocumentException If unable to parse the given text as XML.
 */
public static Document documentFromString(String xml) throws DocumentException {
    Document doc;
    try {
        SAXReader reader = new SAXReader();
        StringReader in = new StringReader(xml);
        doc = reader.read(in);
        in.close();
    } catch (DocumentException e) {
        log.warn("Failed to read the contents of the string as XML:" + xml);
        throw e;
    }
    return doc;
}