Example usage for javax.xml.transform.stream StreamSource setReader

List of usage examples for javax.xml.transform.stream StreamSource setReader

Introduction

In this page you can find the example usage for javax.xml.transform.stream StreamSource setReader.

Prototype

public void setReader(Reader reader) 

Source Link

Document

Set the input to be a character reader.

Usage

From source file:Main.java

public static Schema getSchema(String schemaString) {
    Schema schema = null;//from ww w . j  a  v a2  s . c o m
    try {
        if (schemaString != null) {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            StreamSource ss = new StreamSource();
            ss.setReader(new StringReader(schemaString));
            schema = sf.newSchema(ss);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to create schemma from string: " + schemaString, e);
    }
    return schema;
}

From source file:org.apache.xmlgraphics.image.loader.util.ImageUtil.java

/**
 * Removes any references to InputStreams or Readers from the given Source to prohibit
 * accidental/unwanted use by a component further downstream.
 * @param src the Source object//from   ww w . j  a  v  a  2s  .  co m
 */
public static void removeStreams(Source src) {
    if (src instanceof ImageSource) {
        ImageSource isrc = (ImageSource) src;
        isrc.setImageInputStream(null);
    } else if (src instanceof StreamSource) {
        StreamSource ssrc = (StreamSource) src;
        ssrc.setInputStream(null);
        ssrc.setReader(null);
    } else if (src instanceof SAXSource) {
        InputSource is = ((SAXSource) src).getInputSource();
        if (is != null) {
            is.setByteStream(null);
            is.setCharacterStream(null);
        }
    }
}

From source file:org.apache.xmlgraphics.image.loader.util.ImageUtil.java

/**
 * Closes the InputStreams or ImageInputStreams of Source objects. Any exception occurring
 * while closing the stream is ignored.// ww  w.  java2  s .c  o  m
 * @param src the Source object
 */
public static void closeQuietly(Source src) {
    if (src == null) {
        return;
    } else if (src instanceof StreamSource) {
        StreamSource streamSource = (StreamSource) src;
        IOUtils.closeQuietly(streamSource.getInputStream());
        streamSource.setInputStream(null);
        IOUtils.closeQuietly(streamSource.getReader());
        streamSource.setReader(null);
    } else if (src instanceof ImageSource) {
        ImageSource imageSource = (ImageSource) src;
        if (imageSource.getImageInputStream() != null) {
            try {
                imageSource.getImageInputStream().close();
            } catch (IOException ioe) {
                //ignore
            }
            imageSource.setImageInputStream(null);
        }
    } else if (src instanceof SAXSource) {
        InputSource is = ((SAXSource) src).getInputSource();
        if (is != null) {
            IOUtils.closeQuietly(is.getByteStream());
            is.setByteStream(null);
            IOUtils.closeQuietly(is.getCharacterStream());
            is.setCharacterStream(null);
        }
    }
}