Example usage for java.lang StringBuffer delete

List of usage examples for java.lang StringBuffer delete

Introduction

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

Prototype

@Override
public synchronized StringBuffer delete(int start, int end) 

Source Link

Usage

From source file:com.qmetry.qaf.automation.step.client.text.BehaviorScanner.java

public static ArrayList<Object[]> scan(String strFile) {
    ArrayList<Object[]> rows = new ArrayList<Object[]>();
    File textFile;/*from   w w w. ja va 2  s  .com*/
    int lineNo = 0;

    BufferedReader br = null;
    try {

        logger.info("loading text file: " + strFile);
        textFile = new File(strFile);
        br = new BufferedReader(new FileReader(textFile));
        String strLine = "";
        // file line by line
        // exclude blank lines and comments
        StringBuffer currLineBuffer = new StringBuffer();
        while ((strLine = br.readLine()) != null) {
            // record line number
            lineNo++;
            /**
             * ignore if line is empty or comment line
             */
            if (!("".equalsIgnoreCase(strLine.trim())
                    || COMMENT_CHARS.contains("" + strLine.trim().charAt(0)))) {
                currLineBuffer.append((strLine.trim()));

                if (strLine.endsWith(LINE_BREAK)) {
                    /*
                     * Statement not completed. Remove line break character
                     * and continue statement reading from next line
                     */
                    currLineBuffer.delete(currLineBuffer.length() - LINE_BREAK.length(),
                            currLineBuffer.length());

                } else {
                    // process single statement
                    Object[] cols = new Object[] { "", "", "", lineNo };
                    String currLine = currLineBuffer.toString();
                    if ((StringUtil.indexOfIgnoreCase(currLine, AbstractScenarioFileParser.SCENARIO) == 0)
                            || (StringUtil.indexOfIgnoreCase(currLine,
                                    AbstractScenarioFileParser.STEP_DEF) == 0)
                            || (StringUtil.indexOfIgnoreCase(currLine, "META") == 0)) {

                        System.arraycopy(currLine.split(":", 2), 0, cols, 0, 2);

                        // append meta-data in last/scenario statement
                        if (StringUtil.indexOfIgnoreCase(((String) cols[0]).trim(), "META") == 0) {
                            Object[] row = new Object[4];
                            int prevIndex = rows.size() - 1;

                            Object[] prevRow = rows.remove(prevIndex);

                            System.arraycopy(prevRow, 0, row, 0, 2);
                            row[2] = ((String) cols[1]).trim();
                            row[3] = prevRow[3];
                            rows.add(row);
                            currLineBuffer = new StringBuffer();
                            continue;
                        }
                    } else {
                        // this is a statement
                        cols[0] = currLine;
                    }
                    rows.add(cols);
                    currLineBuffer = new StringBuffer();

                }
            }
        }
    } catch (Exception e) {
        String strMsg = "Exception while reading BDD file: " + strFile + "#" + lineNo;
        logger.error(strMsg + e);
        throw new AutomationError(strMsg, e);

    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    return rows;
}

From source file:ch.qos.logback.core.pattern.parser2.PatternParser.java

/**
 * Unescapes (removes escape sequence) regex characters in a substring. This
 * is the converse of {@link #escapeRegexChars(StringBuffer, int, int)}.
 *
 * @param s string buffer, containing the substring to be unescaped; escape sequences are
 * removed from literals in this buffer//from  w ww .ja va 2s.c o  m
 * @param start zero-based starting character position within {@code s} to be unescaped
 * @param length number of characters of substring
 * @return number of characters removed from the string buffer
 */
static private int unescapeRegexChars(StringBuffer s, int start, int length) {
    String substr = s.substring(start, start + length);
    int numRemovedChars = 0;
    Matcher matcher = REGEX_CHARS_PATTERN.matcher(substr);

    while (matcher.find()) {
        int idxOfRegexChar = matcher.start() - numRemovedChars + start;
        int idxOfEscSeq = idxOfRegexChar - ESC_SEQ_LEN;

        if (idxOfEscSeq >= 0) {
            String prefix = s.substring(idxOfEscSeq, idxOfRegexChar);
            if (prefix.equals(ESC_SEQ)) {
                s.delete(idxOfEscSeq, idxOfRegexChar);
                numRemovedChars += ESC_SEQ_LEN;
            }
        }
    }
    return numRemovedChars;
}

From source file:com.vmware.bdd.utils.CommonUtil.java

public static <K, V> String inputsConvert(Map<K, V> wordsMap) {
    StringBuffer wordsBuff = new StringBuffer();
    if (wordsMap != null && !wordsMap.isEmpty()) {
        for (Entry<K, V> entry : wordsMap.entrySet()) {
            wordsBuff.append(entry.getKey()).append(":").append(entry.getValue()).append(",");
        }/*w w w  .  j  ava2 s. c o m*/
        wordsBuff.delete(wordsBuff.length() - 1, wordsBuff.length());
    }
    return wordsBuff.toString();
}

From source file:org.seasar.mayaa.impl.util.StringUtil.java

/**
 * ???/*from www.ja v a  2 s  .co  m*/
 * hostPage?path???????
 *
 * @param hostPage ??? ("/"?)
 * @param path ? ("/"?)
 * @return hostPage?path??????
 */
public static String adjustContextRelativePath(String hostPage, String path) {
    if (isEmpty(hostPage) || isEmpty(path) || (path.startsWith("/") == false)) {
        return path;
    }

    String[] hostPath = hostPage.split("/");
    String[] linkPath = path.split("/");

    int matchedDirs = 1;// ?????1?
    while (hostPath.length > matchedDirs && linkPath.length > matchedDirs
            && hostPath[matchedDirs].equals(linkPath[matchedDirs])) {
        matchedDirs += 1;
    }

    int depth = hostPath.length - (matchedDirs + 1);

    StringBuffer sb = new StringBuffer();
    sb.append(times("../", depth));

    for (int i = matchedDirs; linkPath.length > i; i++) {
        sb.append(linkPath[i]);
        sb.append('/');
    }
    if (path.charAt(path.length() - 1) != '/') {
        sb.delete(sb.length() - 1, sb.length());
    }

    return sb.toString();
}

From source file:org.apache.velocity.tools.view.ImportSupport.java

/**
 * Strips a servlet session ID from <tt>url</tt>.  The session ID
 * is encoded as a URL "path parameter" beginning with "jsessionid=".
 * We thus remove anything we find between ";jsessionid=" (inclusive)
 * and either EOS or a subsequent ';' (exclusive).
 *
 * @param url the url to strip the session id from
 * @return the stripped url/*from  w  ww  .jav a 2 s  .  c om*/
 */
public static String stripSession(String url) {
    StringBuffer u = new StringBuffer(url);
    int sessionStart;
    while ((sessionStart = u.toString().indexOf(";jsessionid=")) != -1) {
        int sessionEnd = u.toString().indexOf(";", sessionStart + 1);
        if (sessionEnd == -1) {
            sessionEnd = u.toString().indexOf("?", sessionStart + 1);
        }
        if (sessionEnd == -1) {
            // still
            sessionEnd = u.length();
        }
        u.delete(sessionStart, sessionEnd);
    }
    return u.toString();
}

From source file:org.apache.hadoop.hbase.backup.master.FullTableBackupProcedure.java

/**
 * Get backup request meta data dir as string.
 * @param backupInfo backup context/*from ww w.  ja  v a  2  s  .  c o  m*/
 * @return meta data dir
 */
private static String obtainBackupMetaDataStr(BackupInfo backupInfo) {
    StringBuffer sb = new StringBuffer();
    sb.append("type=" + backupInfo.getType() + ",tablelist=");
    for (TableName table : backupInfo.getTables()) {
        sb.append(table + ";");
    }
    if (sb.lastIndexOf(";") > 0) {
        sb.delete(sb.lastIndexOf(";"), sb.lastIndexOf(";") + 1);
    }
    sb.append(",targetRootDir=" + backupInfo.getTargetRootDir());

    return sb.toString();
}

From source file:org.mycore.common.xml.MCRXMLFunctions.java

/**
 * Strippes HTML tags from string./*  ww w  .j  a v a 2s .  c o  m*/
 * 
 * @param s string to strip HTML tags of
 * @return the plain text without tags
 */
public static String stripHtml(final String s) {
    StringBuffer res = new StringBuffer(s);

    Matcher m;
    while ((m = TAG_PATTERN.matcher(res.toString())).find()) {
        res.delete(m.start(), m.end());
        res.insert(m.start(), stripHtml(m.group(m.groupCount() - 1)));
    }

    return StringEscapeUtils.unescapeHtml(res.toString()).replaceAll(TAG_SELF_CLOSING, "");
}

From source file:ruige.GrabFTPDateManager.java

private static void moveDBToRealTable() throws Exception {
    DBUtil db = null;//  w ww. j a  v  a 2s  .  c  o  m
    StringBuffer sql = new StringBuffer();
    try {
        db = DBUtil.getInstance();
        db.setConnectionAttr(false);
        //
        sql.append(
                "update SSRESOrderInfo set HandleStatus = 2 where companyType=0 and (HandleStatus = 0 or HandleStatus = 5)");
        db.execute(sql.toString());
        sql.delete(0, sql.length());
        sql.append(
                "select a.*,DATEDIFF(d,createtime,getdate()) as diffDay, b.ID as TradeTypeID from SSRESOrderInfo as a ")
                .append(" left outer join SSTradeType as b on a.TRADE_MODE=b.TypeCode where companyType=0 and a.HandleStatus = 2 ");
        ArrayList<HashMap<String, String>> OrderList = DBCommon.listBySQL(sql.toString());
        for (int i = 0; i < OrderList.size(); i++) {
            //SSDeclearOrderDetail
            HashMap<String, String> orderht = (HashMap<String, String>) OrderList.get(i);
            HashMap<String, String> ht = new HashMap<String, String>();

            sql.delete(0, sql.length());
            sql.append("select ID, DeclearOrderID from SSDeclearOrderDetail where Declear_NO = '")
                    .append(orderht.get("PRE_ENTRY_ID")).append("'");
            HashMap<String, String> detailht = DBCommon.getBySQL(sql.toString());
            String OrderID = "";
            if (detailht != null && detailht.get("DeclearOrderID") != null
                    && detailht.get("DeclearOrderID").toString().length() > 0) {
                OrderID = detailht.get("DeclearOrderID").toString();
            }

            if (OrderID.length() == 0) { //seastar
                sql.delete(0, sql.length());
                if (Integer.parseInt(orderht.get("diffDay").toString()) > 7) {
                    sql.append("update SSRESOrderInfo set HandleStatus = 10 where companyType=0 and ID = ")
                            .append(orderht.get("ID"));
                } else {
                    sql.append("update SSRESOrderInfo set HandleStatus = 5 where companyType=0 and ID = ")
                            .append(orderht.get("ID"));
                }
                db.execute(sql.toString());
                continue;
            }
            //
            sql.delete(0, sql.length());
            sql.append("select count(1) as LianNum from SSRESPartsList where OrderID = ")
                    .append(orderht.get("ID"));
            String LianDanNum = db.loadVal(sql.toString());
            int dLianDanNum = Integer.parseInt(LianDanNum);
            if (dLianDanNum <= 5) {
                dLianDanNum = 0;
            } else if (dLianDanNum > 5 && dLianDanNum <= 10) { //5
                dLianDanNum = 1;
            } else if (dLianDanNum > 10 && dLianDanNum <= 15) { //5
                dLianDanNum = 2;
            } else if (dLianDanNum > 15 && dLianDanNum <= 20) { //5
                dLianDanNum = 3;
            }
            if (dLianDanNum < 0) {
                dLianDanNum = 0;
            }
            ht.put("DeclearOrderID", OrderID);
            ht.put("TradeTypeID", orderht.get("TradeTypeID"));
            ht.put("Declear_NO", orderht.get("PRE_ENTRY_ID"));
            ht.put("BoxNum", orderht.get("PACK_NO"));
            ht.put("GrossWeight", orderht.get("GROSS_WT"));
            ht.put("NetWeight", orderht.get("GROSS_WT"));
            ht.put("ContractNo", orderht.get("CONTR_NO"));
            ht.put("CUTMode", orderht.get("CUT_MODE"));
            ht.put("ManualNO", orderht.get("MANUAL_NO"));
            ht.put("APPRNO", orderht.get("APPR_NO"));
            ht.put("LicenseNo", orderht.get("LICENSE_NO"));
            ht.put("LianDanNum", dLianDanNum + "");
            ht.put("Remark", orderht.get("NOTE_S"));
            ht.put("ID", detailht.get("ID"));
            db.update(ht, "SSDeclearOrderDetail");
            //
            sql.delete(0, sql.length());
            sql.append("select * from SSRESPartsList where OrderID = ").append(orderht.get("ID"));
            ArrayList<HashMap<String, String>> partsList = DBCommon.listBySQL(sql.toString());
            int hasgoods = 0;
            if (partsList != null && partsList.size() > 0) { //
                sql.delete(0, sql.length());
                sql.append("delete from SSDeclearPartDescription where Declear_NO = '")
                        .append(orderht.get("PRE_ENTRY_ID")).append("'");
                db.execute(sql.toString());
                for (int j = 0; j < partsList.size(); j++) {
                    HashMap<String, String> partsht = (HashMap<String, String>) partsList.get(j);
                    if (partsht.get("G_NAME") == null || partsht.get("G_NAME").toString().length() == 0) {
                        continue;
                    }
                    //
                    sql.delete(0, sql.length());
                    sql.append("select ID from SSGoods where GoodsNo = '").append(partsht.get("CODE_T"))
                            .append("' and GoodsName = '").append(partsht.get("G_NAME")).append("'");
                    String strGoodID = db.loadVal(sql.toString());
                    if (strGoodID.length() == 0) {
                        HashMap<String, String> goodht = new HashMap<String, String>();
                        goodht.put("GoodsNo", partsht.get("CODE_T"));
                        goodht.put("GoodsName", partsht.get("G_NAME"));
                        goodht.put("GoodsMode", partsht.get("G_MODEL"));
                        strGoodID = db.insert(goodht, "SSGoods");
                    } else { //
                        HashMap<String, String> goodht = new HashMap<String, String>();
                        goodht.put("GoodsNo", partsht.get("CODE_T"));
                        goodht.put("GoodsName", partsht.get("G_NAME"));
                        goodht.put("GoodsMode", partsht.get("G_MODEL"));
                        goodht.put("ID", strGoodID);
                        db.update(goodht, "SSGoods");
                    }
                    HashMap<String, String> needht = new HashMap<String, String>();
                    needht.put("OrderId", OrderID);
                    if (partsht.get("MANUAL_NO") != null && partsht.get("MANUAL_NO").toString().length() > 0) {
                        needht.put("ManualNO", orderht.get("MANUAL_NO"));
                    }
                    needht.put("Declear_NO", orderht.get("PRE_ENTRY_ID"));
                    if (partsht.get("G_NO") != null && partsht.get("G_NO").toString().length() > 0) {
                        needht.put("G_NO", partsht.get("G_NO"));
                    }
                    if (partsht.get("CONTR_ITEM") != null
                            && partsht.get("CONTR_ITEM").toString().length() > 0) {
                        needht.put("CONTR_ITEM", partsht.get("CONTR_ITEM"));
                    }
                    needht.put("GoodsID", strGoodID);
                    needht.put("GoodsNo", partsht.get("CODE_T"));
                    needht.put("AddCODE", partsht.get("CODE_S"));
                    needht.put("PartDescription", partsht.get("G_NAME").toString());
                    needht.put("GoodsMode", partsht.get("G_MODEL"));
                    needht.put("ShenBaoQty", partsht.get("G_QTY"));
                    needht.put("ShenBaoUnit", partsht.get("G_UNIT"));
                    needht.put("MuDiCountry", partsht.get("ORIGIN_COUNTRY"));
                    if (partsht.get("DECL_PRICE") != null
                            && partsht.get("DECL_PRICE").toString().length() > 0) {
                        needht.put("Price", partsht.get("DECL_PRICE"));
                    }
                    needht.put("TotalMoney", partsht.get("TRADE_TOTAL"));
                    needht.put("CurrencyCode", partsht.get("TRADE_CURR"));
                    needht.put("FaDingQty", partsht.get("QTY_1"));
                    needht.put("FaDingUnit", partsht.get("UNIT_1"));
                    needht.put("TradeMode", partsht.get("DUTY_MODE"));
                    //
                    db.insert(needht, "SSDeclearPartDescription");
                    hasgoods = 1;
                }
            }
            if (hasgoods == 0) {
                sql.delete(0, sql.length());
                sql.append("update SSRESOrderInfo set HandleStatus = 5 where companyType=0 and ID = ")
                        .append(orderht.get("ID"));
                db.execute(sql.toString());
            }
        }
        //
        sql.delete(0, sql.length());
        sql.append("update SSRESOrderInfo set HandleStatus = 1 where companyType=0 and HandleStatus = 2 ");
        db.execute(sql.toString());

        db.commitConn();
    } catch (Exception e) {
        System.out.println(sql.toString());
        db.rollBackConn();
        e.printStackTrace();
    }
}

From source file:org.hdiv.util.HDIVUtil.java

/**
 * Strips a servlet session ID from <tt>url</tt>. The session ID is encoded as a URL "path parameter" beginning with
 * "jsessionid=". We thus remove anything we find between ";jsessionid=" (inclusive) and either EOS or a subsequent
 * ';' (exclusive)./*from  w w w  .  j a va2 s  .  co  m*/
 * 
 * @param url
 *            url
 * @return url without sessionId
 */
public static String stripSession(String url) {

    if (log.isDebugEnabled()) {
        log.debug("Stripping jsessionid from url " + url);
    }
    StringBuffer u = new StringBuffer(url);
    int sessionStart;

    while (((sessionStart = u.toString().indexOf(";jsessionid=")) != -1)
            || ((sessionStart = u.toString().indexOf(";JSESSIONID=")) != -1)) {

        int sessionEnd = u.toString().indexOf(";", sessionStart + 1);
        if (sessionEnd == -1) {
            sessionEnd = u.toString().indexOf("?", sessionStart + 1);
        }
        if (sessionEnd == -1) { // still
            sessionEnd = u.length();
        }
        u.delete(sessionStart, sessionEnd);
    }
    return u.toString();
}

From source file:org.yestech.lib.util.DecoderUtil.java

private static void uriDecode(final StringBuffer buffer, final int offset, final int length) {
    int index = offset;
    int count = length;
    for (; count > 0; count--, index++) {
        final char ch = buffer.charAt(index);
        if (ch != '%') {
            continue;
        }/* w w  w .  jav a 2 s .c  om*/
        if (count < 3) {
            throw new RuntimeException(
                    "invalid-escape-sequence.error: " + buffer.substring(index, index + count));
        }

        // Decode
        int dig1 = Character.digit(buffer.charAt(index + 1), 16);
        int dig2 = Character.digit(buffer.charAt(index + 2), 16);
        if (dig1 == -1 || dig2 == -1) {
            throw new RuntimeException("invalid-escape-sequence.error " + buffer.substring(index, index + 3));
        }
        char value = (char) (dig1 << 4 | dig2);

        // Replace
        buffer.setCharAt(index, value);
        buffer.delete(index + 1, index + 3);
        count -= 2;
    }
}