List of usage examples for java.io PushbackReader read
public int read() throws IOException
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;/*www. j a v a 2 s . c om*/ } 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.//w w w .j a va 2 s .c o 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()); }