Example usage for java.io PushbackReader unread

List of usage examples for java.io PushbackReader unread

Introduction

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

Prototype

public void unread(char cbuf[]) throws IOException 

Source Link

Document

Pushes back an array of characters by copying it to the front of the pushback buffer.

Usage

From source file:nl.armatiek.xslweb.serializer.RequestSerializer.java

private void serializeBody(List<FileItem> fileItems) throws Exception {
    if (!req.getMethod().equals("POST") || fileItems != null) {
        return;/* w ww  .j a v  a 2  s.  co  m*/
    }
    PushbackReader pushbackReader = new PushbackReader(req.getReader());
    int b = pushbackReader.read();
    if (b == -1) {
        return;
    }
    pushbackReader.unread(b);
    xsw.writeStartElement(URI, "body");
    String contentType = req.getContentType();
    if (contentType != null && contentType.contains(";")) {
        contentType = contentType.split(";")[0].trim();
    }
    if ((contentType != null) && (contentType.startsWith("text/xml")
            || contentType.startsWith("application/xml") || contentType.endsWith("+xml"))) {
        getFilteredXMLReader().parse(new InputSource(pushbackReader));
    } else if ((contentType != null) && contentType.startsWith("text/plain")) {
        xsw.writeCharacters(IOUtils.toString(pushbackReader));
    } else {
        xsw.writeCData(Base64.encodeBase64String(IOUtils.toByteArray(pushbackReader, "UTF-8")));
    }
    xsw.writeEndElement();
}

From source file:org.deegree.framework.xml.XMLFragment.java

/**
 * Initializes the <code>XMLFragment</code> with the content from the given <code>Reader</code>. Sets the SystemId,
 * too./*  www  .  ja va 2s .  co m*/
 * 
 * @param reader
 * @param systemId
 *            can not be null. This string should represent a URL that is related to the passed reader. If this URL
 *            is not available or unknown, the string should contain the value of XMLFragment.DEFAULT_URL
 * @throws SAXException
 * @throws IOException
 * @throws NullPointerException
 */
public void load(Reader reader, String systemId) throws SAXException, IOException {

    PushbackReader pbr = new PushbackReader(reader, 1024);
    int c = pbr.read();
    if (c != 65279 && c != 65534) {
        // no BOM! push char back into reader
        pbr.unread(c);
    }

    InputSource source = new InputSource(pbr);
    if (systemId == null) {
        throw new NullPointerException("'systemId' must not be null!");
    }
    setSystemId(systemId);
    DocumentBuilder builder = XMLTools.getDocumentBuilder();
    Document doc = builder.parse(source);
    setRootElement(doc.getDocumentElement());
}