Example usage for java.io StringWriter write

List of usage examples for java.io StringWriter write

Introduction

In this page you can find the example usage for java.io StringWriter write.

Prototype

public void write(String str) 

Source Link

Document

Write a string.

Usage

From source file:Main.java

public static String toString(XMLEvent event) {
    final StringWriter writer = new StringWriter();
    try {/*from  w  ww  .ja v a 2  s. co m*/
        event.writeAsEncodedUnicode(writer);
    } catch (XMLStreamException e) {
        writer.write(event.toString());
    }

    return writer.toString();
}

From source file:Main.java

/**
 * @param str//from www. java 2s  . co  m
 * @return a code snippet ready to copy and paste into java code.
 */
public static String escapedJavaStringConstant(String str) {
    if (str == null) {
        return null;
    }
    try {
        StringWriter writer = new StringWriter(str.length() * 2);
        writer.write("String s = \"");
        escapeJavaStringConstant(writer, str, true);
        writer.write("\";");
        return writer.toString();
    } catch (IOException ioe) {
        // this should never ever happen while writing to a StringWriter
        ioe.printStackTrace();
        return null;
    }
}

From source file:org.kuali.rice.core.test.JAXBAssert.java

public static void assertEqualXmlMarshalUnmarshalWithResource(Object objectToMarshal, InputStream expectedXml,
        Class<?>... classesToBeBound) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(expectedXml));
    StringWriter writer = new StringWriter();
    int data = -1;
    while ((data = reader.read()) != -1) {
        writer.write(data);
    }//from w w w. j a  va 2 s  .c om
    assertEqualXmlMarshalUnmarshal(objectToMarshal, writer.toString(), classesToBeBound);
}

From source file:Main.java

/**
 * Makes a tag string readable when rendered in HTML. The method
 * escapes all the angle brackets and inserts spaces before and
 * after tags so a browser will wrap the text correctly.
 * This method is used in many places to return an XML string to the
 * user in the event of an error.//from ww w . ja  v a2 s  .com
 * @param tagString the string containing XML tags.
 * @return the readable tag string, or "null" if tagString is null.
 */
public static String makeReadableTagString(String tagString) {
    if (tagString == null)
        return "null";
    StringWriter sw = new StringWriter();
    char c;
    for (int i = 0; i < tagString.length(); i++) {
        c = tagString.charAt(i);
        if (c == '<')
            sw.write(" &#60;"); //note the leading space
        else if (c == '>')
            sw.write("&#62; "); //note the trailing space
        else if (c == '&')
            sw.write("&#38;");
        else if (c == '\"')
            sw.write("&#34;");
        else
            sw.write(c);
    }
    return sw.toString();
}

From source file:com.espertech.esper.pattern.EvalAuditInstanceCount.java

private static void print(EvalAuditStateNode current, String patternExpression, String engineURI,
        String statementName, boolean added, int count) {
    if (!AuditPath.isInfoEnabled()) {
        return;//from  w w  w .  j  a  v  a2 s  . co m
    }

    StringWriter writer = new StringWriter();
    EvalAuditStateNode.writePatternExpr(current, patternExpression, writer);

    if (added) {
        writer.write(" increased to " + count);
    } else {
        writer.write(" decreased to " + count);
    }

    AuditPath.auditLog(engineURI, statementName, AuditEnum.PATTERNINSTANCES, writer.toString());
}

From source file:com.espertech.esper.pattern.EvalAuditStateNode.java

protected static void writePatternExpr(EvalAuditStateNode current, String patternExpression,
        StringWriter writer) {
    if (patternExpression != null) {
        writer.write('(');
        writer.write(patternExpression);
        writer.write(')');
    } else {//from  w ww .j  a  v  a2 s .com
        JavaClassHelper.writeInstance(writer, "subexr", current);
    }
}

From source file:com.signavio.warehouse.business.util.jpdl4.JsonToJpdl.java

public static String transformRequieredAttribute(String name, String value) throws InvalidModelException {
    if (value == null)
        throw new InvalidModelException("Attribute " + name + " is missing.");

    value = StringEscapeUtils.escapeXml(value);

    StringWriter jpdl = new StringWriter();

    jpdl.write(" ");
    jpdl.write(name);/*from   w  w  w .j  ava2s . com*/
    jpdl.write("=\"");
    jpdl.write(value);
    jpdl.write("\"");

    return jpdl.toString();
}

From source file:com.signavio.warehouse.business.util.jpdl4.JsonToJpdl.java

public static String transformAttribute(String name, String value) {
    if (value == null)
        return "";
    if (value.equals(""))
        return "";

    value = StringEscapeUtils.escapeXml(value);

    StringWriter jpdl = new StringWriter();

    jpdl.write(" ");
    jpdl.write(name);//from w ww.j a  v  a  2s  . co  m
    jpdl.write("=\"");
    jpdl.write(value);
    jpdl.write("\"");

    return jpdl.toString();
}

From source file:ch.entwine.weblounge.common.impl.util.html.HTMLUtils.java

/**
 * <p>//from w ww  .  j  ava  2 s. c  o  m
 * Escapes the characters in the <code>String</code> passed and writes the
 * result to the <code>Writer</code> passed.
 * </p>
 * 
 * @param writer
 *          The <code>Writer</code> to write the results of the escaping to.
 *          Assumed to be a non-null value.
 * @param str
 *          The <code>String</code> to escape. Assumed to be a non-null value.
 * 
 * @see #escapeHtml(String)
 */
public static String escapeHtml(String str) {
    StringWriter writer = createStringWriter(str);
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (c > 0x7F) {
            writer.write("&#");
            writer.write(Integer.toString(c, 10));
            writer.write(';');
        } else {
            writer.write(c);
        }
    }
    return writer.toString();
}

From source file:com.espertech.esper.pattern.EvalAuditStateNode.java

private static String toStringEvaluateTrue(EvalAuditStateNode current, String patternExpression,
        MatchedEventMap matchEvent, EvalStateNode fromNode, boolean isQuitted) {

    StringWriter writer = new StringWriter();

    writePatternExpr(current, patternExpression, writer);
    writer.write(" evaluate-true {");

    writer.write(" from: ");
    JavaClassHelper.writeInstance(writer, fromNode, false);

    writer.write(" map: {");
    String delimiter = "";
    Object[] data = matchEvent.getMatchingEvents();
    for (int i = 0; i < data.length; i++) {
        String name = matchEvent.getMeta().getTagsPerIndex()[i];
        Object value = matchEvent.getMatchingEventAsObject(i);
        writer.write(delimiter);/*from   ww  w  . j  a v a  2  s.c om*/
        writer.write(name);
        writer.write("=");
        if (value instanceof EventBean) {
            writer.write(((EventBean) value).getUnderlying().toString());
        } else if (value instanceof EventBean[]) {
            writer.write(EventBeanUtility.summarize((EventBean[]) value));
        }
        delimiter = ", ";
    }

    writer.write("} quitted: ");
    writer.write(Boolean.toString(isQuitted));

    writer.write("}");
    return writer.toString();
}