Example usage for java.lang StringBuffer length

List of usage examples for java.lang StringBuffer length

Introduction

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

Prototype

@Override
    public synchronized int length() 

Source Link

Usage

From source file:edu.iu.dymoro.RotationUtil.java

public static void printRotateOrder(int[] order, int numWorkers) {
    if (order != null) {
        int rowLen = 2 * numWorkers - 1;
        int numIterations = order.length / rowLen;
        StringBuffer sb = new StringBuffer();
        int orderIndex = 0;
        for (int i = 0; i < numIterations; i++) {
            for (int j = 0; j < rowLen; j++) {
                sb.append(order[orderIndex++] + " ");
            }//ww w . j  a  v  a 2  s . c  o  m
            LOG.info(sb);
            sb.delete(0, sb.length());
        }
    }
}

From source file:info.magnolia.cms.core.Path.java

/**
 * <p>//  w  w w . j  a  va 2  s . c om
 * Replace illegal characters by [_] [0-9], [A-Z], [a-z], [-], [_]
 * </p>
 * @param label label to validate
 * @return validated label
 */
public static String getValidatedLabel(String label) {
    StringBuffer s = new StringBuffer(label);
    StringBuffer newLabel = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        int charCode = s.charAt(i);
        // charCodes: 48-57: [0-9]; 65-90: [A-Z]; 97-122: [a-z]; 45: [-]; 95:[_]
        if (((charCode >= 48) && (charCode <= 57)) || ((charCode >= 65) && (charCode <= 90))
                || ((charCode >= 97) && (charCode <= 122)) || charCode == 45 || charCode == 95) {
            newLabel.append(s.charAt(i));
        } else {
            newLabel.append("-"); //$NON-NLS-1$
        }
    }
    if (newLabel.length() == 0) {
        newLabel.append(DEFAULT_UNTITLED_NODE_NAME);
    }
    return newLabel.toString();
}

From source file:com.pureinfo.tgirls.servlet.GetPic.java

public static String idListToString(List<String> _viewdPicIds) {
    if (_viewdPicIds == null) {
        return "";
    }//w ww .j a  v  a  2 s .  c om
    StringBuffer sbuff = new StringBuffer();
    for (Iterator iterator = _viewdPicIds.iterator(); iterator.hasNext();) {
        String string = (String) iterator.next();

        if (sbuff.length() == 0) {
            sbuff.append(string);
        } else {
            sbuff.append(",").append(string);
        }
    }
    return sbuff.toString();
}

From source file:com.clearcenter.mobile_demo.mdRest.java

static private StringBuffer ProcessRequest(HttpsURLConnection http) throws IOException {
    http.connect();//from  w w  w.  j ava  2  s.com

    Log.d(TAG, "Result code: " + http.getResponseCode() + ", content type: " + http.getContentType()
            + ", content length: " + http.getContentLength());

    // Read response, 8K buffer
    BufferedReader buffer = new BufferedReader(new InputStreamReader(http.getInputStream()), 8192);

    String data;
    StringBuffer response = new StringBuffer();
    while ((data = buffer.readLine()) != null)
        response.append(data);

    Log.d(TAG, "Response buffer length: " + response.length());

    buffer.close();
    http.disconnect();

    return response;
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static void addSimpleTextToView(Context context, ArrayList<View> views, StringBuffer buffer,
        LinearLayout.LayoutParams params) {
    if (buffer.length() > 0) {
        views.add(getTextView(context, params, buffer));
        buffer.delete(0, buffer.length());
    }//from ww w.ja va  2s  .  c  o  m
}

From source file:Main.java

public static String unescapeCode(String str) throws IOException {
    StringBuffer sb = new StringBuffer(str.length());
    int sz = str.length();
    StringBuffer unicode = new StringBuffer(4);
    boolean hadSlash = false;
    boolean inUnicode = false;
    for (int i = 0; i < sz; i++) {
        char ch = str.charAt(i);
        if (inUnicode) {
            unicode.append(ch);//from  ww  w. ja  v  a  2  s  .c om
            if (unicode.length() == 4) {
                try {
                    int value = Integer.parseInt(unicode.toString(), 16);
                    sb.append((char) value);
                    unicode.setLength(0);
                    inUnicode = false;
                    hadSlash = false;
                } catch (NumberFormatException nfe) {
                    // ignore
                }
            }
            continue;
        }
        if (hadSlash) {
            hadSlash = false;
            switch (ch) {
            case '\\':
                sb.append('\\');
                break;
            case '\'':
                sb.append('\'');
                break;
            case '\"':
                sb.append('"');
                break;
            case 'r':
                sb.append('\r');
                break;
            case 'f':
                sb.append('\f');
                break;
            case 't':
                sb.append('\t');
                break;
            case 'n':
                sb.append('\n');
                break;
            case 'b':
                sb.append('\b');
                break;
            case 'u': {
                inUnicode = true;
                break;
            }
            default:
                sb.append(ch);
                break;
            }
            continue;
        } else if (ch == '\\') {
            hadSlash = true;
            continue;
        }
        sb.append(ch);
    }
    if (hadSlash) {
        sb.append('\\');
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Normalize a uri containing ../ and ./ paths.
 *
 * @param uri The uri path to normalize//from   www .  j  av a2 s  . com
 * @return The normalized uri
 */
public static String normalize(String uri) {
    if ("".equals(uri)) {
        return uri;
    }
    int leadingSlashes;
    for (leadingSlashes = 0; leadingSlashes < uri.length()
            && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) {
    }
    boolean isDir = (uri.charAt(uri.length() - 1) == '/');
    StringTokenizer st = new StringTokenizer(uri, "/");
    LinkedList clean = new LinkedList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if ("..".equals(token)) {
            if (!clean.isEmpty() && !"..".equals(clean.getLast())) {
                clean.removeLast();
                if (!st.hasMoreTokens()) {
                    isDir = true;
                }
            } else {
                clean.add("..");
            }
        } else if (!".".equals(token) && !"".equals(token)) {
            clean.add(token);
        }
    }
    StringBuffer sb = new StringBuffer();
    while (leadingSlashes-- > 0) {
        sb.append('/');
    }
    for (Iterator it = clean.iterator(); it.hasNext();) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append('/');
        }
    }
    if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') {
        sb.append('/');
    }
    return sb.toString();
}

From source file:FileUtils.java

public static String relativePath(String fromPath, String toPath, boolean fromIsDirectory, char separatorChar) {
    ArrayList<String> fromElements = splitPath(fromPath);
    ArrayList<String> toElements = splitPath(toPath);
    while (!fromElements.isEmpty() && !toElements.isEmpty()) {
        if (!(fromElements.get(0).equals(toElements.get(0)))) {
            break;
        }//  ww w  . j  av a2 s. c  o  m
        fromElements.remove(0);
        toElements.remove(0);
    }

    StringBuffer result = new StringBuffer();
    for (int i = 0; i < fromElements.size() - (fromIsDirectory ? 0 : 1); i++) {
        result.append("..");
        result.append(separatorChar);
    }
    for (String s : toElements) {
        result.append(s);
        result.append(separatorChar);
    }
    return result.substring(0, result.length() - 1);
}

From source file:org.zywx.wbpalmstar.plugin.uexzxing.qrcode.decoder.DecodedBitStreamParser.java

private static void decodeAlphanumericSegment(BitSource bits, StringBuffer result, int count,
        boolean fc1InEffect) throws FormatException {
    // Read two characters at a time
    int start = result.length();
    while (count > 1) {
        int nextTwoCharsBits = bits.readBits(11);
        result.append(toAlphaNumericChar(nextTwoCharsBits / 45));
        result.append(toAlphaNumericChar(nextTwoCharsBits % 45));
        count -= 2;//from   ww w.  j av a  2  s.c o m
    }
    if (count == 1) {
        // special case: one character left
        result.append(toAlphaNumericChar(bits.readBits(6)));
    }
    // See section 6.4.8.1, 6.4.8.2
    if (fc1InEffect) {
        // We need to massage the result a bit if in an FNC1 mode:
        for (int i = start; i < result.length(); i++) {
            if (result.charAt(i) == '%') {
                if (i < result.length() - 1 && result.charAt(i + 1) == '%') {
                    // %% is rendered as %
                    result.deleteCharAt(i + 1);
                } else {
                    // In alpha mode, % should be converted to FNC1 separator 0x1D
                    result.setCharAt(i, (char) 0x1D);
                }
            }
        }
    }
}

From source file:com.microsoft.intellij.util.WAHelper.java

public static WindowsAzureRole prepareRoleToAdd(WindowsAzureProjectManager waProjManager) {
    WindowsAzureRole windowsAzureRole = null;
    try {// w  w w. j av a2 s.c om
        StringBuffer strBfr = new StringBuffer(message("dlgWorkerRole1"));
        int roleNo = 2;
        while (!waProjManager.isAvailableRoleName(strBfr.toString())) {
            strBfr.delete(10, strBfr.length());
            strBfr.append(roleNo++);
        }
        String strKitLoc = WAHelper.getTemplateFile(message("pWizStarterKit"));
        windowsAzureRole = waProjManager.addRole(strBfr.toString(), strKitLoc);
        windowsAzureRole.setInstances(message("rolsNoOfInst"));
        windowsAzureRole.setVMSize(message("rolsVMSmall"));
    } catch (Exception e) {
        log(e.getMessage());
    }
    return windowsAzureRole;
}