List of usage examples for java.io StringWriter append
public StringWriter append(char c)
From source file:com.ibm.watson.developer_cloud.professor_languo.model.stack_exchange.User.java
@Override public String toString() { StringWriter w = new StringWriter(); w.append("\n<User>\n"); w.append("\t{id: " + id.toString() + "\n"); w.append("\treputation: " + printIfNotNull(reputation) + "\n"); w.append("\tdisplayName: " + printIfNotNull(displayName) + "\n"); w.append("\temailHash: " + printIfNotNull(emailHash) + "\n"); w.append("\tcreationDate: " + printIfNotNull(creationDate) + "\n"); w.append("\tlastAccessDate: " + printIfNotNull(lastAccessDate) + "\n"); w.append("\twebsiteUrl: " + printIfNotNull(websiteUrl) + "\n"); w.append("\tlocation: " + printIfNotNull(location) + "\n"); w.append("\tage: " + printIfNotNull(age) + "\n"); w.append("\tupVotes: " + printIfNotNull(upVotes) + "\n"); w.append("\tdownVotes: " + printIfNotNull(downVotes) + "\n"); w.append("\taccountId: " + printIfNotNull(accountId) + "\n"); w.append("\taboutMe: " + printIfNotNull(aboutMe)); w.append("\n\t}\n"); return w.toString(); }
From source file:org.apache.solr.handler.dataimport.processor.PlainTextEntityProcessor.java
@Override public Map<String, Object> nextRow() { if (ended)//from w w w. java2s . c o m return null; final DataSource<Reader> ds = context.getDataSource(); final String url = context.replaceTokens(context.getEntityAttribute(URL)); Reader r = null; try { r = ds.getData(url); } catch (final Exception e) { wrapAndThrow(SEVERE, e, "Exception reading url : " + url); } final StringWriter sw = new StringWriter(); final char[] buf = new char[1024]; while (true) { int len = 0; try { len = r.read(buf); } catch (final IOException e) { IOUtils.closeQuietly(r); wrapAndThrow(SEVERE, e, "Exception reading url : " + url); } if (len <= 0) break; sw.append(new String(buf, 0, len)); } final Map<String, Object> row = new HashMap<String, Object>(); row.put(PLAIN_TEXT, sw.toString()); ended = true; IOUtils.closeQuietly(r); return row; }
From source file:eu.apenet.dpt.standalone.gui.batch.ConvertAndValidateActionListener.java
private String createXmlQualityString(XmlQualityCheckerCall xmlQualityCheckerCall) { StringWriter writer = new StringWriter(); writer.append("\r\n"); writer.append("\r\n"); writer.append("----- "); writer.append(labels.getString("dataquality.title")); writer.append(" -----"); writer.append("\r\n"); writer.append(MessageFormat.format(labels.getString("dataquality.missing.unittitle"), "(unittitle)")); writer.append(" "); writer.append(Integer.toString(xmlQualityCheckerCall.getCounterUnittitle())); writer.append("\r\n"); writer.append(MessageFormat.format(labels.getString("dataquality.missing.unitdate"), "(unitdate@normal)")); writer.append(" "); writer.append(Integer.toString(xmlQualityCheckerCall.getCounterUnitdate())); writer.append("\r\n"); writer.append(MessageFormat.format(labels.getString("dataquality.missing.dao"), "(dao@xlink:role)")); writer.append(" "); writer.append(Integer.toString(xmlQualityCheckerCall.getCounterDao())); writer.append("\r\n"); writer.append(MessageFormat.format(labels.getString("dataquality.missing.href"), "(dao@xlink:href)")); writer.append(" "); writer.append(Integer.toString(xmlQualityCheckerCall.getCounterWrongHref())); return writer.toString(); }
From source file:com.qpark.eip.core.spring.PayloadLogger.java
/** * {@link Message} to string./*from w w w .j av a 2 s . c om*/ * * @param message * the {@link Message}. * @return the {@link Message} as string. */ private String getMessage(final Message<?> message) { Object logMessage = this.expression.getValue(this.evaluationContext, message); if (JAXBElement.class.isInstance(logMessage)) { final JAXBElement<?> elem = (JAXBElement<?>) logMessage; try { if (Objects.nonNull(this.jaxb2Marshaller)) { final StringResult sw = new StringResult(); this.jaxb2Marshaller.marshal(logMessage, sw); logMessage = sw.toString(); } else { final Marshaller marshaller = this.getMarshaller(); if (Objects.nonNull(marshaller)) { final StringWriter sw = new StringWriter(); marshaller.marshal(logMessage, sw); logMessage = sw.toString(); } } } catch (final Exception e) { logMessage = elem.getValue(); } } else if (logMessage instanceof Throwable) { final StringWriter stringWriter = new StringWriter(); if (logMessage instanceof AggregateMessageDeliveryException) { stringWriter.append(((Throwable) logMessage).getMessage()); for (final Exception exception : (List<? extends Exception>) ((AggregateMessageDeliveryException) logMessage) .getAggregatedExceptions()) { exception.printStackTrace(new PrintWriter(stringWriter, true)); } } else { ((Throwable) logMessage).printStackTrace(new PrintWriter(stringWriter, true)); } logMessage = stringWriter.toString(); } final StringBuffer sb = new StringBuffer(1024); sb.append(MessageHeaders.ID).append("=").append(message.getHeaders().getId()); final Object correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId(); if (correlationId != null) { sb.append(", "); sb.append(IntegrationMessageHeaderAccessor.CORRELATION_ID).append("=").append(correlationId); } sb.append("\n"); sb.append(String.valueOf(logMessage)); return sb.toString(); }
From source file:nl.knaw.dans.dccd.rest.AbstractProjectResource.java
/** * Append the permission related information of the project * /*from ww w. ja v a 2 s . co m*/ * @param sw * writer to append to * @param dccdSB * search result */ protected void appendProjectPermissionAsXml(java.io.StringWriter sw, DccdSB dccdSB) { // only the default level sw.append("<permission>"); sw.append(getXMLElementString("defaultLevel", //dccdSB.getPermissionDefaultLevel())); MAP_PERMISSION_TO_ENTITYLEVEL .get(ProjectPermissionLevel.valueOf(dccdSB.getPermissionDefaultLevel())))); sw.append("</permission>"); }
From source file:co.uk.sentinelweb.drawcustom.api.DrawCustomSetTemplate.java
public boolean fromJSON(File f) { if (f.exists()) { try {//from www.j a va 2 s .co m StringWriter sw = new StringWriter(); BufferedReader reader = new BufferedReader(new FileReader(f)); String readline = ""; while ((readline = reader.readLine()) != null) { sw.append(readline); } return fromJSON(sw.toString()); } catch (FileNotFoundException e) { Log.d(DrawCustomGlobals.TAG, "Error reading template:" + f.getAbsolutePath(), e); return false; } catch (IOException e) { Log.d(DrawCustomGlobals.TAG, "Error reading template:" + f.getAbsolutePath(), e); return false; } } return false; }
From source file:dk.dr.radio.data.EoDiverse.java
/** * Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports only HTML 3.0 entities. * Kilde: http://stackoverflow.com/questions/994331/java-how-to-decode-html-character-entities-in-java-like-httputility-htmldecode *//*from w w w .j av a 2 s. co m*/ public static final String unescapeHtml3(final String input) { StringWriter writer = null; int len = input.length(); int i = 1; int st = 0; while (true) { // look for '&' while (i < len && input.charAt(i - 1) != '&') i++; if (i >= len) break; // found '&', look for ';' int j = i; while (j < len && j < i + MAX_ESCAPE + 1 && input.charAt(j) != ';') j++; if (j == len || j < i + MIN_ESCAPE || j == i + MAX_ESCAPE + 1) { i++; continue; } // found escape if (input.charAt(i) == '#') { // numeric escape int k = i + 1; int radix = 10; final char firstChar = input.charAt(k); if (firstChar == 'x' || firstChar == 'X') { k++; radix = 16; } try { int entityValue = Integer.parseInt(input.substring(k, j), radix); if (writer == null) writer = new StringWriter(input.length()); writer.append(input.substring(st, i - 1)); if (entityValue > 0xFFFF) { final char[] chrs = Character.toChars(entityValue); writer.write(chrs[0]); writer.write(chrs[1]); } else { writer.write(entityValue); } } catch (NumberFormatException ex) { i++; continue; } } else { // named escape CharSequence value = lookupMap.get(input.substring(i, j)); if (value == null) { i++; continue; } if (writer == null) writer = new StringWriter(input.length()); writer.append(input.substring(st, i - 1)); writer.append(value); } // skip escape st = j + 1; i = st; } if (writer != null) { writer.append(input.substring(st, len)); return writer.toString(); } return input; }
From source file:ro.nextreports.engine.util.QueryUtil.java
public List<NameType> executeQueryForColumnNames(String sql) throws Exception { // long t = System.currentTimeMillis(); StringWriter sw = new StringWriter(100); // sw.append("SELECT * FROM ("); sw.append(sql); // sw.append(") A WHERE 1 = -1"); String sqlForHeader = sw.toString(); LOG.info("call for header columns = " + sqlForHeader); ResultSet rs = null;//from w w w .j a v a 2 s. com Statement stmt = null; try { if (isProcedureCall(sqlForHeader)) { Dialect dialect = DialectUtil.getDialect(con); CallableStatement cs = con.prepareCall("{" + sqlForHeader + "}"); stmt = cs; if (dialect.hasProcedureWithCursor()) { cs.registerOutParameter(1, dialect.getCursorSqlType()); } rs = cs.executeQuery(); if (dialect.hasProcedureWithCursor()) { rs = (ResultSet) (cs.getObject(1)); } } else { stmt = con.createStatement(); stmt.setMaxRows(1); rs = stmt.executeQuery(sqlForHeader); } ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); List<NameType> columnNames = new ArrayList<NameType>(); for (int i = 0; i < columnCount; i++) { columnNames.add(new NameType(rsmd.getColumnLabel(i + 1), dialect.getJavaType( rsmd.getColumnTypeName(i + 1), rsmd.getPrecision(i + 1), rsmd.getScale(i + 1)))); // rsmd.getColumnClassName(i + 1))); } // t = System.currentTimeMillis() - t; // System.out.println("execute query for column names in " + t + // "ms"); return columnNames; } finally { ConnectionUtil.closeResultSet(rs); ConnectionUtil.closeStatement(stmt); } }
From source file:nl.knaw.dans.dccd.rest.AbstractProjectResource.java
protected void appendProjectDescriptionAsXml(java.io.StringWriter sw, DccdSB dccdSB) { if (dccdSB.hasTridasProjectDescription()) sw.append(getXMLElementString("description", dccdSB.getTridasProjectDescription())); }
From source file:Main.java
public static String getXMLContent(XMLEventReader reader, StartElement element, boolean decodeCharacters) throws XMLStreamException { String rootElementName = getLocalName(element); StringWriter buffer = new StringWriter(1024); StartElement pendingElement = null; String pendingElementName = null; while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (pendingElement != null) { boolean skip = false; if (event.isEndElement() && pendingElementName.equals(getLocalName(event.asEndElement()))) { writeAsEncodedUnicode(pendingElement, buffer, true); // empty tag skip = true; // skip this end tag } else { writeAsEncodedUnicode(pendingElement, buffer, false); }// www. j a v a 2s .c o m pendingElement = null; pendingElementName = null; if (skip) continue; } if (event.isEndElement()) { EndElement endElement = event.asEndElement(); String name = getLocalName(endElement); if (rootElementName.equals(name)) return buffer.toString(); writeAsEncodedUnicode(endElement, buffer); } else if (event.isStartElement()) { pendingElement = event.asStartElement(); pendingElementName = getLocalName(pendingElement); } else if (event.isCharacters() && decodeCharacters) { buffer.append(event.asCharacters().getData()); } else { event.writeAsEncodedUnicode(buffer); } } throw new XMLStreamException(format("Missing closing tag for '" + rootElementName + "' element", element)); }