Example usage for java.lang StringBuffer setLength

List of usage examples for java.lang StringBuffer setLength

Introduction

In this page you can find the example usage for java.lang StringBuffer setLength.

Prototype

@Override
public synchronized void setLength(int newLength) 

Source Link

Usage

From source file:com.panet.imeta.core.row.ValueDataUtil.java

/**
 * Right pad a StringBuffer: adds spaces to a string until a certain length.
 * If the length is smaller then the limit specified, the String is truncated.
 * @param ret The StringBuffer to pad//w ww. j  a  v a 2s .  c  o  m
 * @param limit The desired length of the padded string.
 * @return The padded String.
 */
public static final String rightPad(StringBuffer ret, int limit) {
    int len = ret.length();
    int l;

    if (len > limit) {
        ret.setLength(limit);
    } else {
        for (l = len; l < limit; l++)
            ret.append(' ');
    }
    return ret.toString();
}

From source file:com.camel.framework.tag.ScriptTag.java

/**
 * ?? Minify?script??/*  w  w w.j ava 2s  .  c  om*/
 * 
 * @param sb
 * @param resourcesUrl
 * @param out
 */
private void parseToMinifyStyle(StringBuffer sb, String resourcesUrl, JspWriter out) {
    sb.setLength(0);
    sb.append("<script type='").append(type).append("' data-config='").append(data_config)
            .append("' data-main='").append(data_main).append("' src='").append(resourcesUrl).append("min/?");

    // path?b
    if (StringUtils.isNotBlank(path)) {
        sb.append("b=").append(path).append("&");
    }

    sb.append("f=").append(src).append("'></script>");

    try {
        // ??script?
        out.println(sb.toString());

    } catch (IOException e) {
        logger.error("Could not print out value '" + sb.toString(), e);
    }
}

From source file:org.apache.jackrabbit.standalone.cli.info.Help.java

/**
 * Writes help for all the commands/* w  w w  . j  av a2s. co  m*/
 * @param ctx
 *        the current working <code>Context</code>
 * @throws CommandException
 */
private void helpAll(Context ctx) throws CommandException {
    PrintWriter out = CommandHelper.getOutput(ctx);
    Collection descriptors = factory.getCommandLines();
    Iterator iter = descriptors.iterator();

    // Tab position
    int tabPos = 20;
    while (iter.hasNext()) {
        CommandLine desc = (CommandLine) iter.next();
        if (desc.getName().length() > tabPos) {
            tabPos = desc.getName().length() + 1;
        }
    }

    iter = descriptors.iterator();
    while (iter.hasNext()) {
        CommandLine desc = (CommandLine) iter.next();
        StringBuffer buf = new StringBuffer(desc.getName());
        buf.setLength(tabPos);
        for (int i = desc.getName().length(); i < buf.length(); i++) {
            buf.setCharAt(i, ' ');
        }
        buf.append(desc.getLocalizedDescription());
        hf.printWrapped(out, 70, tabPos, buf.toString());
    }
}

From source file:com.digitalgeneralists.assurance.ApplicationDelegate.java

public void deleteScan(Scan scan) {
    StringBuffer message = new StringBuffer(256);
    logger.info(message.append("Deleting scan: ").append(scan));
    message.setLength(0);
    message = null;//from ww w  .  j  a  v  a  2  s.com

    DeleteScanWorker thread = new DeleteScanWorker(scan, this.notificationProvider);
    thread.execute();
    thread = null;
}

From source file:TestStore.java

private void dumpRecord(byte[] data, int size, PrintStream out, StringBuffer hexLine, StringBuffer charLine,
        int maxLen) {
    if (size == 0)
        return;// w  w w  .j a v  a2  s  .c  o  m

    hexLine.setLength(0);
    charLine.setLength(0);

    int count = 0;

    for (int i = 0; i < size; ++i) {
        char b = (char) (data[i] & 0xFF);

        if (b < 0x10) {
            hexLine.append('0');
        }

        hexLine.append(Integer.toHexString(b));
        hexLine.append(' ');

        if ((b >= 32 && b <= 127) || Character.isDigit(b) || Character.isLowerCase(b)
                || Character.isUpperCase(b)) {
            charLine.append((char) b);
        } else {
            charLine.append('.');
        }

        if (++count >= maxLen || i == size - 1) {
            while (count++ < maxLen) {
                hexLine.append("   ");
            }

            hexLine.append(' ');
            hexLine.append(charLine.toString());

            out.println(hexLine.toString());

            hexLine.setLength(0);
            charLine.setLength(0);
            count = 0;
        }
    }
}

From source file:com.camel.framework.tag.CssLinkTag.java

/**
 * ?? Minify?link??//from  www . j  a v a  2  s  .  c o m
 * 
 * @param sb
 * @param resourcesUrl
 * @param out
 */
private void parseToMinifyStyle(StringBuffer sb, String resourcesUrl, JspWriter out) {
    // 
    sb.setLength(0);
    // minify?link
    sb.append("<link type='").append(type).append("' rel='").append(rel).append("' href='").append(resourcesUrl)
            .append("min/?");

    if (StringUtils.isNotBlank(path)) {
        sb.append("b=").append(path).append("&");
    }

    sb.append("f=").append(href).append("'/>");

    try {
        // ?
        out.println(sb.toString());

    } catch (IOException e) {
        logger.error("Could not print out value '" + sb.toString(), e);
    }
}

From source file:org.kalypso.wspwin.core.prf.DataBlockWriter.java

private void writeMetadata(final PrintWriter pw) {
    for (int i = 1; i < 14; i++) {
        final String[] line = m_metaMap.get(i) == null ? new String[] { "", "" } : m_metaMap.get(i); //$NON-NLS-1$ //$NON-NLS-2$
        final StringBuffer buffer = new StringBuffer("#"); //$NON-NLS-1$
        buffer.append(line.length > 0 ? line[0] : ""); //$NON-NLS-1$

        if (buffer.length() > 41)
            buffer.setLength(41);
        else {/*  w  ww . j av a2 s  .  c o  m*/
            final int l = 41 - buffer.length();
            final char[] space = new char[l];
            Arrays.fill(space, ' ');

            buffer.append(space);
        }
        buffer.append(line.length > 1 ? line[1] : ""); //$NON-NLS-1$
        pw.println(buffer.toString().trim().substring(1));
    }
}

From source file:com.digitalgeneralists.assurance.ApplicationDelegate.java

public void loadScanResults(Scan scan) {
    StringBuffer message = new StringBuffer(256);
    logger.info(message.append("Loading results for scan: ").append(scan));
    message.setLength(0);
    message = null;/*w w  w. j  a v  a2s.c o m*/

    LoadScanResultsWorker thread = new LoadScanResultsWorker(scan, this.notificationProvider);
    thread.execute();
    thread = null;
}

From source file:com.digitalgeneralists.assurance.ApplicationDelegate.java

public void loadApplicationInitializationState() {
    StringBuffer message = new StringBuffer(256);
    logger.info(message.append("Starting application state initialization."));
    message.setLength(0);
    message = null;/*  w  ww . j  a va  2 s  .  c om*/

    InitializeApplicationStateWorker thread = new InitializeApplicationStateWorker(this.notificationProvider);
    thread.execute();
    thread = null;
}

From source file:com.digitalgeneralists.assurance.ApplicationDelegate.java

public void restoreDeletedItem(ComparisonResult result) {
    StringBuffer message = new StringBuffer(256);
    logger.info(message.append("Restoring deleted item for: ").append(result));
    message.setLength(0);
    message = null;//from  w w w  .j a  v  a 2 s.com

    RestoreDeletedItemWorker thread = new RestoreDeletedItemWorker(result, this.notificationProvider);
    thread.execute();
    thread = null;
}