Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

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

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:com.mingsoft.util.proxy.Proxy.java

/**
 * cookie/*from ww  w.j av a  2s. co  m*/
 * 
 * @param cookies
 *            ?cookie <br>
 * @return cookie
 */
public static String assemblyCookie(List cookies) {
    StringBuffer sbu = new StringBuffer();
    //log.info("cookie?");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = (Cookie) cookies.get(i);
        sbu.append(cookie.getName()).append("=").append(cookie.getValue()).append(";");
        //log.info(cookie.getName() + ":" + cookie.getValue());
    }
    //log.info("?cookie?");
    if (sbu.length() > 0)
        sbu.deleteCharAt(sbu.length() - 1);
    return sbu.toString();
}

From source file:org.omnaest.utils.strings.StringUtils.java

public static String insertString(String baseString, String insertString, int insertPosition,
        boolean overwrite) {
    ////from w  ww. j  a  va 2s .  c o  m
    String retval = null;

    //
    if (insertPosition < baseString.length()) {
        StringBuffer sb = new StringBuffer(baseString);
        for (int iInsertPosition = insertPosition; iInsertPosition < insertPosition + insertString.length()
                && iInsertPosition < baseString.length(); iInsertPosition++) {
            int insertStringSourcePosition = iInsertPosition - insertPosition;
            if (overwrite) {
                sb.deleteCharAt(iInsertPosition);
            }
            sb.insert(iInsertPosition,
                    insertString.substring(insertStringSourcePosition, insertStringSourcePosition + 1));
        }
        retval = sb.toString();
    } else {
        throw new StringIndexOutOfBoundsException();
    }

    //
    return retval;
}

From source file:com.jiangyifen.ec2.globaldata.license.LicenseManager.java

/**
 * "xx-xx-xx-xx-xx-xx"??MAC?//from   w w w.  j  a  v  a  2 s . c o  m
 * 
 * @return
 * @throws Exception
 */
private static List<String> getMacAddressList() {
    List<String> macAddressList = new ArrayList<String>();
    try {
        Enumeration<NetworkInterface> ni = NetworkInterface.getNetworkInterfaces();

        while (ni.hasMoreElements()) {
            NetworkInterface netI = ni.nextElement();

            byte[] bytes = netI.getHardwareAddress();
            if (netI.isUp() && netI != null && bytes != null && bytes.length == 6) {
                StringBuffer sb = new StringBuffer();
                for (byte b : bytes) {
                    // 11110000????4?
                    sb.append(Integer.toHexString((b & 240) >> 4));
                    // 00001111????4?
                    sb.append(Integer.toHexString(b & 15));
                    sb.append("-");
                }
                sb.deleteCharAt(sb.length() - 1);
                macAddressList.add(sb.toString().toLowerCase());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return macAddressList;
}

From source file:com.edgenius.wiki.render.MarkupUtil.java

/**
 * @param sb/*from   w  w w .j  a v a  2 s. c om*/
 * @param slash
 * @return
 */
private static boolean processDoubleSlash(StringBuffer sb, int slash) {
    int currLen;
    boolean odd = slash % 2 != 0;
    if (slash > 1) {
        //if the string is like "\\\", then retrieve back from second last slash and convert double slash "\\" to single escape.
        //the last slash will handle in below
        currLen = sb.length();
        //for easy programming. delete all slash here, then append last slash after all double slash converted to HTML entity. 
        for (int sidx = 1; sidx <= slash; sidx++) {
            sb.deleteCharAt(currLen - sidx);
        }
        //see how many double slash 
        int doubleSlashCount = slash / 2;
        for (int sidx = 0; sidx < doubleSlashCount; sidx++) {
            //replace escaped slash to &#92;
            sb.append(ENTITY_SLASH);
        }
        if (odd)
            sb.append("\\");
    }
    return odd;
}

From source file:org.latticesoft.util.common.ConvertUtil.java

/**
 * Convert a iterator of objects into a string
 *///w ww  .j a  v a  2s.  c o  m
public static String convertIteratorToString(Iterator iter) {
    if (iter == null)
        return null;
    StringBuffer sb = new StringBuffer();
    while (iter.hasNext()) {
        sb.append(iter.next());
        sb.append(StringUtil.NEW_LINE_CHAR);
    }
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.subzero.trafficflow.fragment.BaseFragment.java

public static void getUrl(HashMap map, String sendurl) {
    StringBuffer sbUrl = new StringBuffer();

    //?//  ww w.j  av  a 2 s  . c  o m
    sbUrl.append(UrlConstants.BASE + sendurl);
    //        String methedName = (String) map.get("methodname");
    //        sbUrl.append("/" + methedName);
    //post?

    sbUrl.append("?");

    Iterator iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        String val = entry.getValue() + "";
        if (!StringUtils.isNullOrEmpty(key) && !StringUtils.isNullOrEmpty(val)) {
            sbUrl.append(key + "=");
            sbUrl.append(val + "&");
        }
    }
    sbUrl.deleteCharAt(sbUrl.length() - 1);
    com.subzero.trafficflow.Utils.LogUtil.e("url", sbUrl.toString());

}

From source file:com.qk.applibrary.db.sqlite.SqlBuilder.java

/**
 * ??sql?/*from  w  w w  .j a  v a 2 s . c o m*/
 * @return
 */
public static SqlInfo buildInsertSql(Object entity) {

    List<KeyValue> keyValueList = getSaveKeyValueListByEntity(entity);

    StringBuffer strSQL = new StringBuffer();
    SqlInfo sqlInfo = null;
    if (keyValueList != null && keyValueList.size() > 0) {

        sqlInfo = new SqlInfo();

        strSQL.append("INSERT INTO ");
        strSQL.append(TableInfo.get(entity.getClass()).getTableName());
        strSQL.append(" (");
        for (KeyValue kv : keyValueList) {
            strSQL.append(kv.getKey()).append(",");
            sqlInfo.addValue(kv.getValue());
        }
        strSQL.deleteCharAt(strSQL.length() - 1);
        strSQL.append(") VALUES ( ");

        int length = keyValueList.size();
        for (int i = 0; i < length; i++) {
            strSQL.append("?,");
        }
        strSQL.deleteCharAt(strSQL.length() - 1);
        strSQL.append(")");

        sqlInfo.setSql(strSQL.toString());
    }

    return sqlInfo;
}

From source file:org.opencms.xml.CmsXmlUtils.java

/**
 * Simplifies an Xpath by removing a leading and a trailing slash from the given path.<p> 
 * //from w  ww  . j av  a  2  s.c  om
 * Examples:<br> 
 * <code>title/</code> becomes <code>title</code><br>
 * <code>/title[1]/</code> becomes <code>title[1]</code><br>
 * <code>/title/subtitle/</code> becomes <code>title/subtitle</code><br>
 * <code>/title/subtitle[1]/</code> becomes <code>title/subtitle[1]</code><p>
 * 
 * @param path the path to process
 * @return the input with a leading and a trailing slash removed
 */
public static String simplifyXpath(String path) {

    StringBuffer result = new StringBuffer(path);
    if (result.charAt(0) == '/') {
        result.deleteCharAt(0);
    }
    int pos = result.length() - 1;
    if (result.charAt(pos) == '/') {
        result.deleteCharAt(pos);
    }
    return result.toString();
}

From source file:es.pode.soporte.auditoria.registrar.Registrar.java

/**
 * Metodo copiado de SrvBuscadorServiceImpl para parseo de VSQI. TODO Corregir para
 * hacer un parseo XML mas fiable.//from  w w  w .j  a v  a2  s  .  com
 * 
 * @param queryStatement
 * @return
 */
private static String parsearVSQL(String queryStatement) {

    String c = queryStatement.substring(13, queryStatement.length() - 14);
    StringBuffer terminosBuscados = new StringBuffer();
    String palabrasBuscadas = null;

    log("Query: " + queryStatement);

    while (c.startsWith("<term>")) {
        String term = new String(c.substring(6, c.indexOf("</term>")));
        terminosBuscados.append(term);
        terminosBuscados.append(" ");
        c = c.substring(13 + term.length());
    }

    palabrasBuscadas = terminosBuscados.deleteCharAt(terminosBuscados.length()).toString();
    log(palabrasBuscadas);

    return palabrasBuscadas;
}

From source file:org.latticesoft.util.resource.DatabaseUtil.java

/** 
 * Analyse the SQL string into the components
 * @return a String[] of the components 
 *//*from  w w  w .  j a va 2  s . c  o m*/
private static String[] analyseSelectSQL(String sql) {
    String[] s = null;
    if (sql == null)
        return s;
    sql = sql.trim();
    String ss = sql.toLowerCase();
    if (!ss.startsWith("select"))
        return s;
    int index = ss.indexOf("from");
    if (index < 0)
        return s;
    String cols = sql.substring("select".length(), index).trim();

    if (cols.equals("*")) {
        s = null;
    } else {
        s = StringUtil.tokenizeIntoStringArray(cols, ",");
        // regroup
        int open = 0;
        int close = 0;
        ArrayList result = new ArrayList();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length; i++) {
            sb.append(s[i]).append(",");
            open += StringUtil.countOf(s[i], "(");
            close += StringUtil.countOf(s[i], ")");
            if (open == close) {
                sb.deleteCharAt(sb.length() - 1);
                result.add(sb.toString());
                sb.setLength(0);
                open = 0;
                close = 0;
            }
        }
        s = new String[result.size()];
        s = (String[]) result.toArray(s);

        for (int i = 0; i < s.length; i++) {
            if (s[i] != null) {
                index = s[i].toLowerCase().indexOf(" as ");
                if (index > -1) {
                    s[i] = s[i].substring(index + 4, s[i].length()).trim();
                }
                index = s[i].toLowerCase().indexOf(" ");
                if (index > -1) {
                    s[i] = s[i].substring(index + 1, s[i].length()).trim();
                }
            }
        }
    }
    return s;
}