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:org.apache.james.mime4j.MimeStreamParser.java

/**
 * Parses a header.//from   w w  w. j  a  va  2s . c o m
 * 
 * @param is the stream to parse.
 * @return a <code>BodyDescriptor</code> describing the body following 
 *         the header.
 */
private BodyDescriptor parseHeader(InputStream is) throws IOException {
    BodyDescriptor bd = new BodyDescriptor(
            bodyDescriptors.isEmpty() ? null : (BodyDescriptor) bodyDescriptors.getFirst());

    handler.startHeader();

    int lineNumber = rootStream.getLineNumber();

    StringBuffer sb = new StringBuffer();
    int curr = 0;
    int prev = 0;
    while ((curr = is.read()) != -1) {
        if (curr == '\n' && (prev == '\n' || prev == 0)) {
            /*
             * [\r]\n[\r]\n or an immediate \r\n have been seen.
             */
            sb.deleteCharAt(sb.length() - 1);
            break;
        }
        sb.append((char) curr);
        prev = curr == '\r' ? prev : curr;
    }

    if (curr == -1 && log.isWarnEnabled()) {
        log.warn("Line " + rootStream.getLineNumber() + ": Unexpected end of headers detected. "
                + "Boundary detected in header or EOF reached.");
    }

    int start = 0;
    int pos = 0;
    int startLineNumber = lineNumber;
    while (pos < sb.length()) {
        while (pos < sb.length() && sb.charAt(pos) != '\r') {
            pos++;
        }
        if (pos < sb.length() - 1 && sb.charAt(pos + 1) != '\n') {
            pos++;
            continue;
        }

        if (pos >= sb.length() - 2 || fieldChars.get(sb.charAt(pos + 2))) {

            /*
             * field should be the complete field data excluding the 
             * trailing \r\n.
             */
            String field = sb.substring(start, pos);
            start = pos + 2;

            /*
             * Check for a valid field.
             */
            int index = field.indexOf(':');
            boolean valid = false;
            if (index != -1 && fieldChars.get(field.charAt(0))) {
                valid = true;
                String fieldName = field.substring(0, index).trim();
                for (int i = 0; i < fieldName.length(); i++) {
                    if (!fieldChars.get(fieldName.charAt(i))) {
                        valid = false;
                        break;
                    }
                }

                if (valid) {
                    handler.field(field);
                    bd.addField(fieldName, field.substring(index + 1));
                }
            }

            if (!valid && log.isWarnEnabled()) {
                log.warn("Line " + startLineNumber + ": Ignoring invalid field: '" + field.trim() + "'");
            }

            startLineNumber = lineNumber;
        }

        pos += 2;
        lineNumber++;
    }

    handler.endHeader();

    return bd;
}

From source file:vle.domain.webservice.http.impl.HttpRestTransportImpl.java

/**
 * @see net.sf.sail.webapp.domain.webservice.http.HttpRestTransport#get(net.sf.sail.webapp.domain.webservice.http.HttpGetRequest)
 *//*from   w w w .  j a va2  s . co  m*/
public InputStream get(final HttpGetRequest httpGetRequestData) throws HttpStatusCodeException {
    // add parameters to URL
    Map<String, String> requestParameters = httpGetRequestData.getRequestParameters();
    StringBuffer buffer = new StringBuffer(this.baseUrl);
    buffer.append(httpGetRequestData.getRelativeUrl());
    if (requestParameters != null && !requestParameters.isEmpty()) {
        buffer.append('?');
        Set<String> keys = requestParameters.keySet();
        for (String key : keys) {
            buffer.append(key).append('=').append(requestParameters.get(key)).append('&');
        }
        buffer.deleteCharAt(buffer.length() - 1);
    }

    GetMethod method = new GetMethod(buffer.toString());

    this.setHeaders(httpGetRequestData, method);
    try {
        // Execute the method.
        logRequest(method, "");
        int statusCode = this.client.executeMethod(method);
        httpGetRequestData.isValidResponseStatus(method, statusCode);
        return new ByteArrayInputStream(method.getResponseBody());
    } catch (HttpStatusCodeException hsce) {
        logAndThrowRuntimeException(hsce);
    } catch (HttpException he) {
        logAndThrowRuntimeException(he);
    } catch (IOException ioe) {
        logAndThrowRuntimeException(ioe);
    } finally {
        method.releaseConnection();
    }
    return null;
}

From source file:org.kuali.ext.mm.document.web.struts.CountWorksheetPrintAction.java

private String getDocNumbers(List<WorksheetCountDocument> lisDocs) {

    if (MMUtil.isCollectionEmpty(lisDocs))
        return null;

    StringBuffer sb = new StringBuffer();

    for (WorksheetCountDocument wdoc : lisDocs) {
        sb.append(wdoc.getDocumentNumber()).append(",");
    }/* w w w  . ja v a 2s.  co m*/
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:net.sf.sail.webapp.domain.webservice.http.impl.HttpRestTransportImpl.java

/**
 * @see net.sf.sail.webapp.domain.webservice.http.HttpRestTransport#get(net.sf.sail.webapp.domain.webservice.http.HttpGetRequest)
 *//*from  w w w  .  j  a  va 2s . c  o m*/
public InputStream get(final HttpGetRequest httpGetRequestData) throws HttpStatusCodeException {
    // add parameters to URL
    Map<String, String> requestParameters = httpGetRequestData.getRequestParameters();
    StringBuffer buffer = new StringBuffer(this.baseUrl);
    buffer.append(httpGetRequestData.getRelativeUrl());
    if (requestParameters != null && !requestParameters.isEmpty()) {
        buffer.append('?');
        Set<String> keys = requestParameters.keySet();
        for (String key : keys) {
            buffer.append(key).append('=').append(requestParameters.get(key)).append('&');
        }
        buffer.deleteCharAt(buffer.length() - 1);
    }

    GetMethod method = new GetMethod(buffer.toString());

    this.setHeaders(httpGetRequestData, method);
    try {
        // Execute the method.
        logRequest(method, "");
        int statusCode = this.client.executeMethod(method);
        httpGetRequestData.isValidResponseStatus(method, statusCode);
        return new ByteArrayInputStream(method.getResponseBody());
    } catch (CurnitMapNotFoundException cmnfe) {
        if (logger.isErrorEnabled()) {
            logger.error(cmnfe.getMessage(), cmnfe);
        }
        throw cmnfe;
    } catch (HttpStatusCodeException hsce) {
        logAndThrowRuntimeException(hsce);
    } catch (HttpException he) {
        logAndThrowRuntimeException(he);
    } catch (IOException ioe) {
        logAndThrowRuntimeException(ioe);
    } finally {
        method.releaseConnection();
    }
    return null;
}

From source file:com.clustercontrol.collect.util.CollectGraphUtil.java

/**
 * ??????????//  w  w w  . j a  va2  s. c  o  m
 * ??????
 * @param summaryType
 * @return
 */
public static String drawGraphSheets(int summaryType) {
    long start = System.currentTimeMillis();
    m_log.debug("drawGraphSheets()");
    Long nowDate = System.currentTimeMillis();

    long formatTerm = MILLISECOND_MONTH;
    if (getInstance().m_targetConditionEndDate == null && getInstance().m_targetConditionStartDate == null) {
        // ??null?????(????)??????-1h????
        m_log.debug("drawGraphSheets() first draw.");
        getInstance().m_targetConditionEndDate = nowDate;

        // ?????
        switch (summaryType) {
        case SummaryTypeConstant.TYPE_AVG_HOUR:
        case SummaryTypeConstant.TYPE_MIN_HOUR:
        case SummaryTypeConstant.TYPE_MAX_HOUR:
            // ??????1???1?
            getInstance().m_targetConditionStartDate = nowDate - MILLISECOND_DAY;
            formatTerm = MILLISECOND_WEEK;
            break;

        case SummaryTypeConstant.TYPE_AVG_DAY:
        case SummaryTypeConstant.TYPE_MIN_DAY:
        case SummaryTypeConstant.TYPE_MAX_DAY:
            // ??????1???1?
            getInstance().m_targetConditionStartDate = nowDate - MILLISECOND_WEEK;
            formatTerm = MILLISECOND_MONTH;
            break;

        case SummaryTypeConstant.TYPE_AVG_MONTH:
        case SummaryTypeConstant.TYPE_MIN_MONTH:
        case SummaryTypeConstant.TYPE_MAX_MONTH:
            // ??????1???10?
            getInstance().m_targetConditionStartDate = nowDate - MILLISECOND_YEAR;
            formatTerm = MILLISECOND_10YEAR;
            break;

        default:// raw
            // ??????1???1?
            getInstance().m_targetConditionStartDate = nowDate - MILLISECOND_HOUR;
            formatTerm = MILLISECOND_DAY;
            break;
        }

    } else {
        m_log.debug("drawGraphSheets() already draw.");
        // ?????????????????

        // ?1???????????????12??(??)
        if (isSelectTermOverDay() && summaryType == SummaryTypeConstant.TYPE_RAW) {
            long center = (getSelectTermDiff() / 2) + getInstance().m_targetConditionStartDate;
            getInstance().m_targetConditionStartDate = center - (MILLISECOND_DAY / 2);
            getInstance().m_targetConditionEndDate = center + (MILLISECOND_DAY / 2);
            m_log.debug("drawGraphSheets() summaryType:raw, term over day. shortcut term. center:" + center);
        }
        // ?????????
        formatTerm = getInstance().m_sliderEnd - getInstance().m_sliderStart;

    }
    // ??????
    long centerDate = getTargetConditionStartDate()
            + (getTargetConditionEndDate() - getTargetConditionStartDate()) / 2;
    getInstance().m_sliderStart = centerDate - (formatTerm / 2);
    getInstance().m_sliderEnd = centerDate + (formatTerm / 2);

    // ???
    ArrayList<String> plotJsonList = new ArrayList<>();
    int countgraph = 0;
    int dispCount = ClusterControlPlugin.getDefault().getPreferenceStore()
            .getInt(PerformancePreferencePage.P_GRAPH_MAX);
    boolean allbreak = false;
    boolean itembreak = false;
    for (CollectKeyInfoPK collectKeyInfoPK : getInstance().m_collectKeyInfoList) {
        // manager
        for (Map.Entry<String, TreeMap<String, List<Integer>>> entry : getInstance().m_targetManagerFacilityCollectMap
                .entrySet()) {
            String managerName = entry.getKey();
            Map<String, List<Integer>> facilityCollectMap = entry.getValue();
            for (Map.Entry<String, List<Integer>> faci_entry : facilityCollectMap.entrySet()) {
                String facilityId = faci_entry.getKey();
                // add?
                String params = createBaseGraphDiv(managerName, collectKeyInfoPK.getItemName(),
                        collectKeyInfoPK.getMonitorId(), collectKeyInfoPK.getDisplayName(), facilityId);
                plotJsonList.add(params);
                if (getInstance().totalFlg) {
                    // ????on????itemcode???1???????????break?
                    countgraph += facilityCollectMap.size();
                    if (countgraph >= dispCount) {
                        allbreak = true;
                        break;
                    }
                    itembreak = true;
                    break;
                }
                countgraph++;
                if (countgraph >= dispCount) {
                    allbreak = true;
                    break;
                }
            }
            if (allbreak) {
                break;
            }
            if (itembreak) {
                break;
            }
        }
        if (allbreak) {
            break;
        }
    }

    StringBuffer sb = new StringBuffer();
    for (String plotStr : plotJsonList) {
        sb.append(plotStr);
        sb.append(",");
    }
    sb.insert(0, "{\'all\':[");
    if (plotJsonList.size() > 0) {
        sb.deleteCharAt(sb.length() - 1); // ,??
    }

    sb.append("], ");
    sb.append(orderItemInfoSelection());
    sb.append("}");
    m_log.info("createDrawGraphs() time:" + (System.currentTimeMillis() - start) + "ms");

    return sb.toString();
}

From source file:edu.mayo.bmi.dictionary.jdbc.JdbcDictionaryImpl.java

@SuppressWarnings("rawtypes")
private PreparedStatement initMetaDataPrepStmt(String text) throws SQLException {
    if (iv_mdPrepStmt == null) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT ");

        // translate meta data field names into columns
        // to be returned in the result set
        Iterator metaFieldNameItr = getMetaFieldNames();
        while (metaFieldNameItr.hasNext()) {
            String mdFieldName = (String) metaFieldNameItr.next();
            sb.append(mdFieldName);/*from w w w. jav a2s .  c  om*/
            sb.append(',');
        }
        // chomp off the last comma
        sb.deleteCharAt(sb.length() - 1);

        sb.append(" FROM ");
        sb.append(iv_tableName);

        sb.append(" WHERE ");
        sb.append(iv_lookupFieldName);
        sb.append(" = ?");

        iv_mdPrepStmt = iv_dbConn.prepareStatement(sb.toString());
    }

    iv_mdPrepStmt.clearParameters();
    iv_mdPrepStmt.setString(1, text);

    return iv_mdPrepStmt;
}

From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java

protected String getAppURL(HttpServletRequest httpRequest) {
    log.debug("getAppURL");

    if (isValidStartupPage(httpRequest)) {
        StringBuffer sb = new StringBuffer(VirtualHostHelper.getServerURL(httpRequest));
        if (VirtualHostHelper.getServerURL(httpRequest).endsWith("/")) {
            sb.deleteCharAt(sb.length() - 1);
        }//  w  w  w.  j  a v  a2 s  .  c o  m
        sb.append(httpRequest.getRequestURI());
        if (httpRequest.getQueryString() != null) {
            sb.append("?");
            sb.append(httpRequest.getQueryString());

            // remove ticket parameter from URL to correctly validate the
            // service
            int indexTicketKey = sb.lastIndexOf(ticketKey + "=");
            if (indexTicketKey != -1) {
                sb.delete(indexTicketKey - 1, sb.length());
            }
        }
        log.debug(sb.toString());
        return sb.toString();
    }
    if (appURL == null || appURL.equals("")) {
        log.debug("null app url");
        appURL = NUXEO_SERVER_PATTERN_KEY;
    }
    if (appURL.contains(NUXEO_SERVER_PATTERN_KEY)) {
        String nxurl = BaseURL.getBaseURL(httpRequest);
        log.debug(String.format("nxurl app url : %s", appURL.replace(NUXEO_SERVER_PATTERN_KEY, nxurl)));
        return appURL.replace(NUXEO_SERVER_PATTERN_KEY, nxurl);
    } else {
        log.debug(String.format("appurl: %s", appURL));
        return appURL;
    }
}

From source file:org.netflux.core.Record.java

/**
 * Returns a string representation of this record. The string representation is a comma separated list of values surrounded by square
 * brackets./*from w ww . j av  a 2  s. c  o  m*/
 * 
 * @return a string representation of this record.
 */
@Override
public String toString() {
    StringBuffer recordString = new StringBuffer("[");
    for (Field<? extends Object> field : this.data) {
        recordString.append(field.toString());
        recordString.append(',');
    }
    if (!this.data.isEmpty()) {
        recordString.deleteCharAt(recordString.length() - 1);
    }
    recordString.append(']');
    return recordString.toString();
}

From source file:org.wso2.carbon.identity.relyingparty.saml.tokens.SAML2TokenHolder.java

/**
 * Populates the attributes./*from  w  w  w  .j  ava  2  s  .c o  m*/
 * 
 * @param attributeTable
 */
public void populateAttributeTable(Map<String, String> attributeTable) {
    Iterator<AttributeStatement> statements = assertion.getAttributeStatements().iterator();

    while (statements.hasNext()) {
        AttributeStatement statement = (AttributeStatement) statements.next();
        Iterator<Attribute> attrs = statement.getAttributes().iterator();

        while (attrs.hasNext()) {
            Attribute attr = (Attribute) attrs.next();
            String attrNamesapce = attr.getNameFormat();
            String attrName = attr.getName();
            String name = attrNamesapce + "/" + attrName;

            List attributeValues = attr.getAttributeValues();
            Iterator values = attributeValues.iterator();
            int count = 0;
            StringBuffer buff = new StringBuffer();

            while (values.hasNext()) {
                Object value = values.next();
                if (value instanceof XSString) {
                    buff.append(((XSString) value).getValue());
                } else if (value instanceof XSAny) {
                    buff.append(((XSAny) value).getTextContent());
                }
                buff.append(",");
                count++;
            }

            if (buff.length() > 1) {
                buff.deleteCharAt(buff.length() - 1);
            }

            if (count > 1) {
                isMultipleValues = true;
            }

            attributeTable.put(name, buff.toString());
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("Attribute table populated for SAML 2 Token");
    }
}

From source file:org.wso2.carbon.identity.relyingparty.saml.tokens.SAML1TokenHolder.java

/**
 * Populates the attributes./*  w  w  w .j  av a2  s  .c o m*/
 * 
 * @param attributeTable
 */
public void populateAttributeTable(Map<String, String> attributeTable) {
    Iterator<AttributeStatement> statements = assertion.getAttributeStatements().iterator();

    while (statements.hasNext()) {
        AttributeStatement statement = statements.next();
        Iterator<Attribute> attrs = statement.getAttributes().iterator();

        while (attrs.hasNext()) {
            Attribute attr = (Attribute) attrs.next();
            String name = attr.getAttributeNamespace() + "/" + attr.getAttributeName();

            List attributeValues = attr.getAttributeValues();
            Iterator values = attributeValues.iterator();
            int count = 0;
            StringBuffer buffer = new StringBuffer();

            while (values.hasNext()) {
                Object value = values.next();
                if (value instanceof XSString) {
                    buffer.append(((XSString) value).getValue());
                } else if (value instanceof XSAny) {
                    buffer.append(((XSAny) value).getTextContent());
                }
                buffer.append(",");
                count++;
            }

            if (buffer.length() > 1) {
                buffer.deleteCharAt(buffer.length() - 1);
            }

            if (count > 1) {
                isMultipleValues = true;
            }

            attributeTable.put(name, buffer.toString());
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("Attribute table populated for SAML 1 Token");
    }
}