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:com.github.xbn.testdev.StubFunctionUtil.java

public static final Appendable appendForSourceX(Appendable to_appendTo, File source_code) throws IOException {
    CompositionStubUtil.appendJavaFilePathWithDotsNoDtJava(to_appendTo, source_code);
    to_appendTo.append(LINE_SEP).append(LINE_SEP);
    Iterator<String> li = FileUtils.lineIterator(source_code); //Throws npx if null

    String sClassName = null;/*from www. j  a v  a2 s  . com*/
    while (li.hasNext()) {
        String sLn = StringUtil.ltrim(li.next());
        if (sLn.startsWith(sSTUB_LINE_MARKER_PREFIX)) {
            appendStubsX(to_appendTo, li);
        }
    }
    return to_appendTo;
}

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

private static void writeMultiLine(final Appendable writer, final String element, final int level,
        final ElementPlace elementPlace) throws IOException {
    writer.append("|2-\n");
    final String[] lines = StringUtils.split(element, '\n');
    final int lvl = level + 1;//((elementPlace == ElementPlace.LIST) ? 0 : 1);
    for (int i = 0, linesLength = lines.length; i < linesLength; i++) {
        final String line = lines[i];
        appendElement(writer, lvl, line);
        if ((i + 1) < linesLength) {
            writer.append('\n');
        }/* ww w .j a  va 2 s .c  o  m*/
    }
}

From source file:Main.java

/**
 * XML encodes an attribute value, escaping some characters as
 * character entities, and dropping invalid control characters.
 * <p>/*from   w  ww.java2s.c om*/
 * Only four characters need to be encoded, according to the
 * <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">
 * W3C XML 1.0 Specification Character definition</a>: {@code < & " '}
 * (less-than, ampersand, double-quote, single-quote).
 * <p>
 * Actually, we could only encode one of the quote characters if
 * we knew that that was the one used to wrap the value, but we'll
 * play it safe and encode both.
 * <p>
 * We drop invalid XML characters, following the
 * <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">
 * W3C XML 1.0 Specification Character definition</a>:
 * <pre>
 * Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
 * </pre>
 * Java uses UTF-16 internally, so Unicode characters U+10000 to
 * U+10FFFF are encoded using the surrogate characters excluded
 * above, 0xD800 to 0xDFFF. So we allow just 0x09, 0x0A, 0x0D,
 * and the range 0x20 to 0xFFFD.
 *
 * @param attrValue the attribute value
 * @param buf the {@code Appendable} to which to append the attribute value
 * @throws IOException from {@code Appendable} (but {@code StringBuffer} or
 *        {@code StringBuilder} will never actually throw {@code IOException})
 * @since 2.4
 */
public static void xmlAppendAttrValue(String attrValue, Appendable buf) throws IOException {
    for (int i = 0; i < attrValue.length(); i++) {
        char c = attrValue.charAt(i);
        switch (c) {
        case '<':
            buf.append(XML_LESS_THAN);
            break;
        case '&':
            buf.append(XML_AMPERSAND);
            break;
        case '"':
            buf.append(XML_QUOTE);
            break;
        case '\'':
            buf.append(XML_APOSTROPHE);
            break;
        case '\t':
        case '\n':
        case '\r':
            // TODO: what happens to white-space?
            buf.append(c);
            break;
        default:
            if (c >= 0x20 && c <= 0xFFFD) {
                buf.append(c);
            }
            break;
        }
    }
}

From source file:org.power.commons.lang.util.CollectionUtils.java

/**
 * ?/* w w  w . ja  va2 s .c  o m*/
 */
public static void join(Appendable buf, Iterable<?> objs, String sep) throws IOException {
    if (objs == null) {
        return;
    }

    if (sep == null) {
        sep = BasicConstant.EMPTY_STRING;
    }

    for (Iterator<?> i = objs.iterator(); i.hasNext();) {
        buf.append(String.valueOf(i.next()));

        if (i.hasNext()) {
            buf.append(sep);
        }
    }
}

From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java

private static void appendDir(final Appendable report, final File file, final int indent) throws IOException {
    for (int i = 0; i < indent; i++)
        report.append("  - ");

    final Formatter formatter = new Formatter(report);
    final Calendar calendar = new GregorianCalendar(UTC);
    calendar.setTimeInMillis(file.lastModified());
    formatter.format(Locale.US, "%tF %tT %8d  %s\n", calendar, calendar, file.length(), file.getName());
    formatter.close();//ww w  .  j  a  va 2  s  .c  om

    final File[] files = file.listFiles();
    if (files != null)
        for (final File f : files)
            appendDir(report, f, indent + 1);
}

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

/**
 * Append given char sequence with proper indent.
 *
 * @param writer  {@link Appendable} to use, all data will be added here.
 * @param level   current indent level.//  ww w .  j  a v  a2 s  .  c om
 * @param element text to append.
 *
 * @throws IOException from {@link Appendable}
 */
protected static void appendElement(final Appendable writer, final int level, final CharSequence element)
        throws IOException {
    spaces(writer, level);
    writer.append(element);
}

From source file:de.schildbach.wallet.util.CrashReporter.java

private static void copy(final BufferedReader in, final Appendable out) throws IOException {
    while (true) {
        final String line = in.readLine();
        if (line == null)
            break;

        out.append(line).append('\n');
    }//from ww  w  . jav a 2 s . co m
}

From source file:hydrograph.engine.spark.helper.DelimitedAndFixedWidthHelper.java

private static void appendFiller(Appendable buffer, char filler, int times) throws IOException {
    for (int i = 0; i < times; i++) {
        buffer.append(filler);
    }/*ww  w.j  a  va 2  s .c om*/
}

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

/**
 * Append indent (2 spaces per level)/*from   www . jav  a 2 s .c  o  m*/
 *
 * @param writer {@link Appendable} to use, all data will be added here.
 * @param level  current indent level.
 *
 * @throws IOException from {@link Appendable}
 */
protected static void spaces(final Appendable writer, final int level) throws IOException {
    if (level <= 0) {
        return;
    }
    for (int i = 0; i < level; i++) {
        writer.append("  ");
    }
}

From source file:com.igormaznitsa.mindmap.model.ModelUtils.java

public static void writeChar(@Nonnull final Appendable out, final char chr, final int times)
        throws IOException {
    for (int i = 0; i < times; i++) {
        out.append(chr);
    }/*from w ww.  j a  v a2 s . c o  m*/
}