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.fluidops.iwb.wiki.FluidWikiModel.java

@Override
public void substituteTemplateCall(String templateName, Map<String, String> parameterMap, Appendable writer)
        throws IOException {

    if (!included.contains(templateName)) {
        included.add(templateName);/*  w  w  w.ja v a  2 s .com*/
        super.substituteTemplateCall(templateName, parameterMap, writer);
        included.remove(templateName);
    } else
        writer.append("(Error: infinite loop of template " + templateName + ")");
}

From source file:org.opensingular.form.SType.java

private void debugTypeHeader(Appendable appendable) throws IOException {
    if (isAttribute()) {
        debugTypeHeaderAttribute(appendable);
    } else {/*  ww  w . j  a v a 2s. co  m*/
        debugTypeHeaderNormalType(appendable);
    }
    if (superType != null && (!isAttribute() || !isSelfReference())) {
        appendable.append(" extend ");
        appendNameAndId(appendable, superType);
        if (this.isList()) {
            STypeList<?, ?> lista = (STypeList<?, ?>) this;
            if (lista.getElementsType() != null) {
                appendable.append(" of ");
                appendNameAndId(appendable, lista.getElementsType());
            }
        }
    }
}

From source file:de.micromata.genome.util.runtime.debug.PoorMansStackTraceProfiler.java

/**
 * Dump st list./*from  w  w  w  .ja v a  2 s  . c om*/
 *
 * @param sb the sb
 * @param minCallCount the min call count
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void dumpStList(Appendable sb, int minCallCount) throws IOException {
    List<Pair<Integer, StackTraceElement>> sl = new ArrayList<Pair<Integer, StackTraceElement>>(stm.size());
    for (Map.Entry<StackTraceElement, Holder<Integer>> e : stm.entrySet()) {
        sl.add(Pair.make(e.getValue().get(), e.getKey()));
    }
    Collections.sort(sl, new Comparator<Pair<Integer, StackTraceElement>>() {

        @Override
        public int compare(Pair<Integer, StackTraceElement> o1, Pair<Integer, StackTraceElement> o2) {
            if (o1.getFirst().equals(o2.getFirst()) == true) {
                return 0;
            }
            if (o1.getFirst() < o2.getFirst()) {
                return 1;
            }
            return -1;
        }
    });
    sb.append("\n\nAll Method:\n");
    for (Pair<Integer, StackTraceElement> p : sl) {
        if (p.getFirst() < minCallCount) {
            break;
        }
        sb.append(p.getFirst().toString()).append("  ").append(p.getSecond().toString()).append("\n");
    }

}

From source file:org.apache.logging.log4j.core.util.datetime.FastDatePrinter.java

/**
 * Appends all digits to the given buffer.
 *
 * @param buffer the buffer to append to.
 * @param value the value to append digits from.
 *//*  w w  w. jav  a2 s. c o  m*/
private static void appendFullDigits(final Appendable buffer, int value, int minFieldWidth) throws IOException {
    // specialized paths for 1 to 4 digits -> avoid the memory allocation from the temporary work array
    // see LANG-1248
    if (value < 10000) {
        // less memory allocation path works for four digits or less

        int nDigits = 4;
        if (value < 1000) {
            --nDigits;
            if (value < 100) {
                --nDigits;
                if (value < 10) {
                    --nDigits;
                }
            }
        }
        // left zero pad
        for (int i = minFieldWidth - nDigits; i > 0; --i) {
            buffer.append('0');
        }

        switch (nDigits) {
        case 4:
            buffer.append((char) (value / 1000 + '0'));
            value %= 1000;
        case 3:
            if (value >= 100) {
                buffer.append((char) (value / 100 + '0'));
                value %= 100;
            } else {
                buffer.append('0');
            }
        case 2:
            if (value >= 10) {
                buffer.append((char) (value / 10 + '0'));
                value %= 10;
            } else {
                buffer.append('0');
            }
        case 1:
            buffer.append((char) (value + '0'));
        }
    } else {
        // more memory allocation path works for any digits

        // build up decimal representation in reverse
        final char[] work = new char[MAX_DIGITS];
        int digit = 0;
        while (value != 0) {
            work[digit++] = (char) (value % 10 + '0');
            value = value / 10;
        }

        // pad with zeros
        while (digit < minFieldWidth) {
            buffer.append('0');
            --minFieldWidth;
        }

        // reverse
        while (--digit >= 0) {
            buffer.append(work[digit]);
        }
    }
}

From source file:net.hasor.search.utils.DateUtil.java

/** Formats the date and returns the calendar instance that was used (which may be reused) */
public static Calendar formatDate(Date date, Calendar cal, Appendable out) throws IOException {
    // using a stringBuilder for numbers can be nice since
    // a temporary string isn't used (it's added directly to the
    // builder's buffer.
    StringBuilder sb = out instanceof StringBuilder ? (StringBuilder) out : new StringBuilder();
    if (cal == null)
        cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
    cal.setTime(date);/*from  w  w w.j ava 2s . c om*/
    int i = cal.get(Calendar.YEAR);
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.DAY_OF_MONTH);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('T');
    i = cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.MINUTE);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.SECOND);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    i = cal.get(Calendar.MILLISECOND);
    if (i != 0) {
        sb.append('.');
        if (i < 100)
            sb.append('0');
        if (i < 10)
            sb.append('0');
        sb.append(i);
        // handle canonical format specifying fractional
        // seconds shall not end in '0'.  Given the slowness of
        // integer div/mod, simply checking the last character
        // is probably the fastest way to check.
        int lastIdx = sb.length() - 1;
        if (sb.charAt(lastIdx) == '0') {
            lastIdx--;
            if (sb.charAt(lastIdx) == '0') {
                lastIdx--;
            }
            sb.setLength(lastIdx + 1);
        }
    }
    sb.append('Z');
    if (out != sb)
        out.append(sb);
    return cal;
}

From source file:org.apache.hadoop.hive.ql.optimizer.GenMapRedUtils.java

public static List<Path> getInputPathsForPartialScan(TableScanOperator tableScanOp, Appendable aggregationKey)
        throws SemanticException {
    List<Path> inputPaths = new ArrayList<Path>();
    switch (tableScanOp.getConf().getTableMetadata().getTableSpec().specType) {
    case TABLE_ONLY:
        inputPaths.add(tableScanOp.getConf().getTableMetadata().getTableSpec().tableHandle.getPath());
        break;/*from  w  w w.  j a v a 2 s .c  o  m*/
    case STATIC_PARTITION:
        Partition part = tableScanOp.getConf().getTableMetadata().getTableSpec().partHandle;
        try {
            aggregationKey.append(Warehouse.makePartPath(part.getSpec()));
        } catch (MetaException e) {
            throw new SemanticException(ErrorMsg.ANALYZE_TABLE_PARTIALSCAN_AGGKEY
                    .getMsg(part.getDataLocation().toString() + e.getMessage()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        inputPaths.add(part.getDataLocation());
        break;
    default:
        assert false;
    }
    return inputPaths;
}

From source file:org.apache.solr.common.util.DateUtil.java

/** Formats the date and returns the calendar instance that was used (which may be reused) */
public static Calendar formatDate(Date date, Calendar cal, Appendable out) throws IOException {
    // using a stringBuilder for numbers can be nice since
    // a temporary string isn't used (it's added directly to the
    // builder's buffer.

    StringBuilder sb = out instanceof StringBuilder ? (StringBuilder) out : new StringBuilder();
    if (cal == null)
        cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
    cal.setTime(date);//from  w  ww.  j ava 2 s  .com

    int i = cal.get(Calendar.YEAR);
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.DAY_OF_MONTH);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('T');
    i = cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.MINUTE);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.SECOND);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    i = cal.get(Calendar.MILLISECOND);
    if (i != 0) {
        sb.append('.');
        if (i < 100)
            sb.append('0');
        if (i < 10)
            sb.append('0');
        sb.append(i);

        // handle canonical format specifying fractional
        // seconds shall not end in '0'.  Given the slowness of
        // integer div/mod, simply checking the last character
        // is probably the fastest way to check.
        int lastIdx = sb.length() - 1;
        if (sb.charAt(lastIdx) == '0') {
            lastIdx--;
            if (sb.charAt(lastIdx) == '0') {
                lastIdx--;
            }
            sb.setLength(lastIdx + 1);
        }

    }
    sb.append('Z');

    if (out != sb)
        out.append(sb);

    return cal;
}

From source file:net.sourceforge.seqware.pipeline.plugins.batchmetadatainjection.RunInfo.java

public void print(Appendable writer, Metadata metadata) throws IOException {
    String platform = "<null>";
    if (platformId != null && !platformId.trim().isEmpty() && StringUtils.isNumeric(platformId)) {
        for (Platform p : metadata.getPlatforms()) {
            if (p.getPlatformId().equals(Integer.parseInt(platformId))) {
                platform = p.getName();//  ww w. j  a v  a 2  s  .co  m
            }
        }
    }
    String studyTypeStr = "<null>";
    if (studyType != null && !studyType.trim().isEmpty() && StringUtils.isNumeric(studyType)) {
        for (StudyType st : metadata.getStudyTypes()) {
            if (st.getStudyTypeId().equals(Integer.parseInt(studyType))) {
                studyTypeStr = st.getName();
            }
        }
    }
    writer.append("RunInfo{");
    writer.append("\n\tstudyTitle=").append(studyTitle);
    writer.append("\n\tstudyDescription=").append(studyDescription);
    writer.append("\n\tstudyCenterName=").append(studyCenterName);
    writer.append("\n\tstudyCenterProject=").append(studyCenterProject);
    writer.append("\n\trunName=").append(runName);
    writer.append("\n\trunDescription=").append(runDescription);
    writer.append("\n\trunFilePath=").append(runFilePath);
    writer.append("\n\texperimentName=").append(experimentName);
    writer.append("\n\texperimentDescription=").append(experimentDescription);
    writer.append("\n\tplatform=").append(platform);
    writer.append("\n\tstudyType=").append(studyTypeStr);
    writer.append("\n\tskipRun=").append(String.valueOf(runSkip));
    if (lanes != null)
        for (LaneInfo lane : lanes) {
            lane.print(writer, metadata);
        }
    writer.append("\n\t}");
    writer.append("\n}");
}

From source file:com.cloudlbs.core.utils.DateUtil.java

/**
 * Formats the date and returns the calendar instance that was used (which
 * may be reused)//from  w  w  w  . j  a  va  2  s.c  o m
 */
public static Calendar formatDate(Date date, Calendar cal, Appendable out) throws IOException {
    // using a stringBuilder for numbers can be nice since
    // a temporary string isn't used (it's added directly to the
    // builder's buffer.

    StringBuilder sb = out instanceof StringBuilder ? (StringBuilder) out : new StringBuilder();
    if (cal == null)
        cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
    cal.setTime(date);

    int i = cal.get(Calendar.YEAR);
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.DAY_OF_MONTH);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('T');
    i = cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.MINUTE);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.SECOND);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    i = cal.get(Calendar.MILLISECOND);
    if (i != 0) {
        sb.append('.');
        if (i < 100)
            sb.append('0');
        if (i < 10)
            sb.append('0');
        sb.append(i);

        // handle canonical format specifying fractional
        // seconds shall not end in '0'. Given the slowness of
        // integer div/mod, simply checking the last character
        // is probably the fastest way to check.
        int lastIdx = sb.length() - 1;
        if (sb.charAt(lastIdx) == '0') {
            lastIdx--;
            if (sb.charAt(lastIdx) == '0') {
                lastIdx--;
            }
            sb.setLength(lastIdx + 1);
        }

    }
    sb.append('Z');

    if (out != sb)
        out.append(sb);

    return cal;
}

From source file:org.auraframework.http.AuraTestFilter.java

private void injectScriptTags(Appendable out, String originalResponse, String tags) throws IOException {
    // Look for closing body or html tag and insert before that, otherwise just append to the original.
    // TODO: Inject at top, after Test.js can compile and run separately from Aura.js.
    Matcher bodyMatcher = bodyEndTagPattern.matcher(originalResponse);
    int insertionPoint = originalResponse.length();
    if (bodyMatcher.matches()) {
        insertionPoint = bodyMatcher.start(1);
    } else {/*ww w  . j  a v a2  s.  co  m*/
        Matcher htmlMatcher = htmlEndTagPattern.matcher(originalResponse);
        if (htmlMatcher.matches()) {
            insertionPoint = htmlMatcher.start(1);
        }
    }

    out.append(originalResponse.substring(0, insertionPoint));
    out.append(tags);
    out.append(originalResponse.substring(insertionPoint));
}