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.text.StringUtil.java

/**
   <p>Get one str_obj if a condition is met, another if it's not.</p>
        //w  w w  .jav a2  s.  c o m
 * @param  to_appendTo  May not be {@code null}.
 * @param  true_oString  Returned if {@code condition} is {@code true}.
 * @param  oString_ifFalse  Returned if {@code condition} is {@code false}.
 * @exception  RTIOException  If an {@link java.io.IOException IOException} is thrown
 * @see  #getIfTrueFalse(Object, boolean, Object) getIfTrueFalse(O,b,O)
 */
public static final Appendable appendIfTrueFalse(Appendable to_appendTo, Object true_oString, boolean condition,
        Object oString_ifFalse) {
    try {
        if (condition) {
            if (true_oString != null) {
                to_appendTo.append(true_oString.toString());
            }
        } else if (oString_ifFalse != null) {
            to_appendTo.append(oString_ifFalse.toString());
        }
    } catch (IOException iox) {
        throw new RTIOException("appendIfTrueFalse", iox);
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(to_appendTo, "to_appendTo", null, rx);
    }
    return to_appendTo;
}

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

private static void appendZero(Appendable buffer, int times) throws IOException {
    char filler = ' ';
    for (int i = 0; i < times; i++) {
        buffer.append(filler);
    }//w  ww .j ava 2s .c o  m
}

From source file:org.openlaszlo.sc.ScriptCompiler.java

/** Writes a LaszloScript array literal that evaluates to a
 * LaszloScript array whose elements are LaszloScript
 * representations of the arguments elements.
 *
 * The elements of the list are strings that represent JavaScript
 * expressions, not values.  That is, the value "foo" will compile
 * to a reference to the variable named foo; "'foo'" or "\"foo\""
 * is necessary to enter a string in the array.
 *
 * @param list a list/*from  w  w  w  . j a va2  s  .c  o  m*/
 * @param writer an appendable
 * @return a string
 */
private static void writeList(List<Object> list, Appendable writer) throws IOException {
    writer.append("[");
    for (Iterator<Object> iter = list.iterator(); iter.hasNext();) {
        writeObject(iter.next(), writer);
        if (iter.hasNext()) {
            writer.append(", ");
        }
    }
    writer.append("]");
}

From source file:org.openconcerto.sql.model.SQLSchema.java

public static final void appendVersionAttr(final String version, final Appendable sb) throws IOException {
    if (version != null) {
        sb.append(' ');
        sb.append(VERSION_XMLATTR);//w  ww. j a  v  a2  s  . c o m
        sb.append("=\"");
        sb.append(JDOMUtils.OUTPUTTER.escapeAttributeEntities(version));
        sb.append('"');
    }
}

From source file:password.pwm.util.localdb.LocalDBUtility.java

private static void writeStringToOut(final Appendable out, final String string) {
    if (out == null) {
        return;//from  w w w  . ja v a 2s  . co  m
    }

    final String msg = JavaHelper.toIsoDate(new Date()) + " " + string + "\n";

    try {
        out.append(msg);
    } catch (IOException e) {
        LOGGER.error("error writing to output appender while performing operation: " + e.getMessage()
                + ", message:" + msg);
    }
}

From source file:org.openlaszlo.sc.ScriptCompiler.java

/** Writes a LaszloScript object literal whose properties are the
 * keys of the map and whose property values are the LaszloScript
 * representations of the map's values./*from  w w  w  .  j a  va  2  s  .co  m*/
 *
 * The elements of the map are strings that represent JavaScript
 * expressions, not values.  That is, the value "foo" will compile
 * to a reference to the variable named foo; "'foo'" or "\"foo\""
 * is necessary to enter a string in the map.
 *
 * @param map String -> Object
 * @param writer an appendable
 * @return a string
 */
private static <V> void writeMap(Map<String, Object> map, Appendable writer) throws IOException {
    writer.append("{");
    // Sort the keys, so that regression tests aren't sensitive to
    // the undefined order of iterating a (non-TreeMap) Map.
    SortedMap<String, Object> smap = new TreeMap<String, Object>(map);
    for (Iterator<Map.Entry<String, Object>> iter = smap.entrySet().iterator(); iter.hasNext();) {
        Map.Entry<String, Object> entry = iter.next();
        String key = entry.getKey();
        Object value = entry.getValue();
        if (!isIdentifier(key))
            key = quote(key);
        writer.append(key).append(": ");
        writeObject(value, writer);
        if (iter.hasNext()) {
            writer.append(", ");
        }
    }
    writer.append("}");
}

From source file:Main.java

public static final void print(Appendable out, String start, String delim, String quotStart, String quotEnd,
        String end, Object... array) throws IOException {
    append(start, out);/*from w w  w  .  j  a  v a  2 s .c  o m*/
    boolean first = true;
    for (Object ob : array) {
        if (!first) {
            append(delim, out);
        } else {
            first = false;
        }
        append(quotStart, out);
        out.append(format(ob));
        append(quotEnd, out);
    }
    append(end, out);
}

From source file:org.apache.ofbiz.base.util.UtilIO.java

/** Copy a Reader to an Appendable, optionally closing the input.
 *
 * @param reader the Reader to copy from
 * @param closeIn whether to close the input when the copy is done
 * @param out the Appendable to copy to//from w w  w  .j av a 2  s  .c  o m
 * @throws IOException if an error occurs
 */
public static void copy(Reader reader, boolean closeIn, Appendable out) throws IOException {
    try {
        CharBuffer buffer = CharBuffer.allocate(4096);
        while (reader.read(buffer) > 0) {
            buffer.flip();
            buffer.rewind();
            out.append(buffer);
        }
    } finally {
        if (closeIn)
            IOUtils.closeQuietly(reader);
    }
}

From source file:com.github.xbn.text.StringUtil.java

/**
   <p>Append a str_obj, duplicated.</p>
        // w  w  w  .  jav  a2  s. co  m
 * @param  to_appendTo  May not be {@code null}.
 * @param  str_toDup  Descriptive name of {@code to_appendTo}. <i>Should</i> not be {@code null} or empty.
 * @param  dup_count  <i>Should</i> be greater than zero.
 * @exception  RTIOException  If an {@link java.io.IOException IOException} is thrown.
 * @see  #getDuped(Object, int) getDuped(O,i)
 */
public static final Appendable appendDuped(Appendable to_appendTo, Object str_toDup, int dup_count) {
    try {
        CrashIfString.nullEmpty(str_toDup, "str_toDup", null);
        String s = str_toDup.toString();
        for (int i = 0; i < dup_count; i++) {
            to_appendTo.append(s);
        }
    } catch (IOException iox) {
        throw new RTIOException(iox);
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(to_appendTo, "to_appendTo", null, rx);
    }
    return to_appendTo;
}

From source file:Main.java

/**
 * /*from  ww w. ja  va2s .c o  m*/
 * @param out
 * @param start
 * @param delim
 * @param quotStart
 * @param quotEnd
 * @param end
 * @param collection
 * @throws IOException 
 */
public static final void print(Appendable out, String start, String delim, String quotStart, String quotEnd,
        String end, Collection<?> collection) throws IOException {
    append(start, out);
    boolean first = true;
    for (Object ob : collection) {
        if (!first) {
            append(delim, out);
        } else {
            first = false;
        }
        append(quotStart, out);
        out.append(format(ob));
        append(quotEnd, out);
    }
    append(end, out);
}