Example usage for java.lang Appendable append

List of usage examples for java.lang Appendable append

Introduction

In this page you can find the example usage for java.lang Appendable append.

Prototype

Appendable append(char c) throws IOException;

Source Link

Document

Appends the specified character to this Appendable .

Usage

From source file:ProxyAdapter.java

/**
 * Usage example//from  ww w  . j av a 2 s  .c om
 */
public static void main(String[] args) throws Exception {
    //Create adapter for Appendable
    ProxyAdapter<Appendable> pa = new ProxyAdapter(Appendable.class) {
        private StringBuilder sb = new StringBuilder();

        //Override only 2 methods: append and toString
        public Appendable append(char c) {
            System.out.println("Proxy append(char c) method. Append " + c);
            sb.append(c);
            return (Appendable) getProxy();
        }

        public String toString() {
            return "Proxy toString method: " + sb;
        }

    };
    final Appendable a = pa.getProxy();
    a.append('1').append('2');
    System.out.println("a.toString() = " + a.toString());
    //this invocation fails because no method has been created
    a.append("Not implemented");

}

From source file:Main.java

/**
 * Wraps an xm tag with '&lt;/' and '&gt;'.
 *
 * @param tag the XML tag to wrap with '&lt;/' and '&gt;'
 * @param buf the {@code Appendable} to which to append the start tag
 * @throws IOException from {@code Appendable} (but {@code StringBuffer} or
 *        {@code StringBuilder} will never actually throw {@code IOException})
 * @since 2.4//from   www  .j  ava  2s .c om
 */
public static void xmlAppendEndTag(String tag, Appendable buf) throws IOException {
    buf.append("</");
    buf.append(tag);
    buf.append(">\n");
}

From source file:Main.java

/**
 * Wraps an xm tag with '&lt;' and '&gt;'.
 *
 * @param tag the XML tag to wrap with '&lt;' and '&gt;'
 * @param buf the {@code Appendable} to which to append the start tag
 * @throws IOException from {@code Appendable} (but {@code StringBuffer} or
 *        {@code StringBuilder} will never actually throw {@code IOException})
 * @since 2.4/*  ww  w.j  a  v a 2s.c o m*/
 */
public static void xmlAppendStartTag(String tag, Appendable buf) throws IOException {
    buf.append('<');
    buf.append(tag);
    buf.append('>');
}

From source file:Main.java

/**
 * _more_//from  ww  w  . ja v  a2  s  .c om
 *
 * @param sb _more_
 * @param s _more_
 *
 * @throws Exception _more_
 */
public static void appendCdata(Appendable sb, String s) throws Exception {
    sb.append("<![CDATA[");
    sb.append(s);
    sb.append("]]>");
}

From source file:Main.java

/**
 * Writes the string value of the specified items to appendable,
 * wrapping an eventual IOException into a RuntimeException
 * //from  w  w  w. j a  v a  2s.  co m
 * @param appendable to append values to
 * @param items items to dump
 */
public static void dump(Appendable appendable, Iterable<?> items) {
    try {
        for (Object item : items) {
            appendable.append(String.valueOf(item));
            appendable.append("\n");
        }
    } catch (IOException e) {
        throw new RuntimeException("An error occured while appending", e);
    }
}

From source file:Main.java

/**
 * Writes out an attribute for an element.  If the attribute value
 * is non-{@code null} and non-empty, then the attribute is written out,
 * preceded by a single space./*w  w  w  .  j a va 2  s .c o  m*/
 * The given value will be XML encoded before appending to the buffer.
 * <p>
 * For example, given attrName="foo" and attrValue="val&lt;bar" writes out:
 * <pre>foo="val&amp;lt;bar"</pre>
 *
 * @param attrName the attribute name
 * @param attrValue the attribute value
 * @param buf the {@code Appendable} to which to append the attribute
 *        name-value pair
 * @throws IOException from {@code Appendable} (but {@code StringBuffer} or
 *        {@code StringBuilder} will never actually throw {@code IOException})
 * @since 2.4
 */
public static void xmlAppendAttr(String attrName, String attrValue, Appendable buf) throws IOException {
    if (attrValue != null && attrValue.length() > 0) {
        buf.append(' ');
        buf.append(attrName);
        buf.append("=\"");
        xmlAppendAttrValue(attrValue, buf);
        buf.append('"');
    }
}

From source file:Main.java

private static void append(String str, Appendable out) throws IOException {
    if (str != null) {
        out.append(str);
    }/*from  w  w w .  j  a va 2 s.c  o m*/
}

From source file:org.diorite.cfg.system.elements.StringTemplateElement.java

private static void writeQuoted(final Appendable writer, final String element) throws IOException {
    writer.append('\"');
    writer.append(StringUtils.replaceEach(element, REP_LAST_1, REP_LAST_2));
    writer.append('\"');
}

From source file:org.diorite.cfg.system.elements.StringTemplateElement.java

private static void writeSingleQuoted(final Appendable writer, final String element) throws IOException {
    writer.append('\'');
    writer.append(StringUtils.replace(element, "\n", "\\n"));
    writer.append('\'');
}

From source file:com.github.xbn.testdev.StubFunctionUtil.java

private static final Appendable appendStubFuncForSigLineX(Appendable to_appendTo, String func_sigLine,
        String return_type) throws IOException {
    to_appendTo.append("\t").append(func_sigLine).append(LINE_SEP);
    if (!return_type.equals("void")) {
        Object oDefault = JavaRegexUtil.getInitializedObjectForClassName(return_type);
        to_appendTo.append("\t\treturn  ").append(StringWithNullDefault.get(oDefault, "null")).append(LINE_SEP);
    }/*w w w.j  a  va2s  .c o  m*/
    return to_appendTo.append("\t}").append(LINE_SEP);
}