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:net.sf.zekr.common.util.VelocityUtils.java

public String items2JsArray(int pageNum) {
    IPagingData pagingData = ApplicationConfig.getInstance().getQuranPaging().getDefault();
    IQuranPage quranPage = pagingData.getQuranPage(pageNum);
    IQuranLocation fromLoc = quranPage.getFrom();
    IQuranLocation toLoc = quranPage.getTo();
    StringBuffer buf = new StringBuffer("[");
    while (fromLoc != null && fromLoc.compareTo(toLoc) <= 0) {
        buf.append('\'').append(fromLoc.toString()).append('\'').append(", ");
        fromLoc = fromLoc.getNext();//from w  w w  .j  a va 2  s .  c o  m
    }
    if (buf.length() > 1) {
        buf.replace(buf.length() - 2, buf.length(), "]");
    }
    return buf.toString();
}

From source file:be.ibridge.kettle.trans.step.textfileinput.TextFileInput.java

public static final Row convertLineToRow(LogWriter log, TextFileLine textFileLine, TextFileInputMeta info,
        DecimalFormat ldf, DecimalFormatSymbols ldfs, SimpleDateFormat ldaf, DateFormatSymbols ldafs,
        String fname, long rowNr, FileErrorHandler errorHandler) throws KettleException {

    Row r = new Row();

    if (textFileLine == null || textFileLine.line == null || textFileLine.line.length() == 0)
        return r;

    int fieldnr;//from w  w w.  j a  v a  2  s  .  c  om
    Value value;

    Value errorCount = null;
    if (info.isErrorIgnored() && info.getErrorCountField() != null && info.getErrorCountField().length() > 0) {
        errorCount = new Value(info.getErrorCountField(), 0L);
    }
    Value errorFields = null;
    if (info.isErrorIgnored() && info.getErrorFieldsField() != null
            && info.getErrorFieldsField().length() > 0) {
        errorFields = new Value(info.getErrorFieldsField(), "");
    }
    Value errorText = null;
    if (info.isErrorIgnored() && info.getErrorTextField() != null && info.getErrorTextField().length() > 0) {
        errorText = new Value(info.getErrorTextField(), "");
    }

    int nrfields = info.getInputFields().length;

    try {
        // System.out.println("Convertings line to string ["+line+"]");
        ArrayList strings = convertLineToStrings(log, textFileLine.line, info);

        for (fieldnr = 0; fieldnr < nrfields; fieldnr++) {
            TextFileInputField f = info.getInputFields()[fieldnr];

            String field = fieldnr < nrfields ? f.getName() : "empty" + fieldnr;
            int type = fieldnr < nrfields ? f.getType() : Value.VALUE_TYPE_STRING;
            String format = fieldnr < nrfields ? f.getFormat() : "";
            int length = fieldnr < nrfields ? f.getLength() : -1;
            int precision = fieldnr < nrfields ? f.getPrecision() : -1;
            String group = fieldnr < nrfields ? f.getGroupSymbol() : "";
            String decimal = fieldnr < nrfields ? f.getDecimalSymbol() : "";
            String currency = fieldnr < nrfields ? f.getCurrencySymbol() : "";
            String nullif = fieldnr < nrfields ? f.getNullString() : "";
            String ifnull = fieldnr < nrfields ? f.getIfNullValue() : "";
            int trim_type = fieldnr < nrfields ? f.getTrimType() : TextFileInputMeta.TYPE_TRIM_NONE;

            if (fieldnr < strings.size()) {
                String pol = (String) strings.get(fieldnr);
                try {
                    value = convertValue(pol, field, type, format, length, precision, group, decimal, currency,
                            nullif, ifnull, trim_type, ldf, ldfs, ldaf, ldafs);
                } catch (Exception e) {
                    // OK, give some feedback!
                    String message = "Couldn't parse field [" + field + "] with value [" + pol + "], format ["
                            + format + "] ldaf=[" + ldaf.toLocalizedPattern() + "]";

                    if (info.isErrorIgnored()) {
                        log.logBasic(fname, "WARNING: " + message + " : " + e.getMessage());

                        value = new Value(field, type);
                        value.setNull();

                        if (errorCount != null) {
                            errorCount.plus(1L);
                        }
                        if (errorFields != null) {
                            StringBuffer sb = new StringBuffer(errorFields.getString());
                            if (sb.length() > 0)
                                sb.append(", ");
                            sb.append(field);
                            errorFields.setValue(sb);
                        }
                        if (errorText != null) {
                            StringBuffer sb = new StringBuffer(errorText.getString());
                            if (sb.length() > 0)
                                sb.append(Const.CR);
                            sb.append(message);
                            errorText.setValue(sb);
                        }
                        if (errorHandler != null) {
                            errorHandler.handleLineError(textFileLine.lineNumber,
                                    AbstractFileErrorHandler.NO_PARTS);
                        }

                        if (info.isErrorLineSkipped())
                            r.setIgnore();
                    } else {
                        throw new KettleException(message, e);
                    }
                }
            } else {
                // No data found: TRAILING NULLCOLS: add null value...
                value = new Value(field, type);
                value.setNull();
            }

            // Now add value to the row!
            r.addValue(value);
        }

        // Add the error handling fields...
        if (errorCount != null)
            r.addValue(errorCount);
        if (errorFields != null)
            r.addValue(errorFields);
        if (errorText != null)
            r.addValue(errorText);

        // Support for trailing nullcols!
        if (fieldnr < info.getInputFields().length) {
            for (int i = fieldnr; i < info.getInputFields().length; i++) {
                TextFileInputField f = info.getInputFields()[i];

                value = new Value(f.getName(), f.getType()); // build a
                // value!
                value.setLength(f.getLength(), f.getPrecision());
                value.setNull();
                r.addValue(value);
            }
        }
    } catch (Exception e) {
        throw new KettleException("Error converting line", e);
    }

    // Possibly add a filename...
    if (info.includeFilename()) {
        Value inc = new Value(info.getFilenameField(), fname);
        inc.setLength(100);
        r.addValue(inc);
    }

    // Possibly add a row number...
    if (info.includeRowNumber()) {
        Value inc = new Value(info.getRowNumberField(), Value.VALUE_TYPE_INTEGER);
        inc.setValue(rowNr);
        inc.setLength(9);
        r.addValue(inc);
    }

    return r;
}

From source file:com.bstek.dorado.common.service.ExposedServiceAnnotationBeanPostProcessor.java

@Override
public void onStartup() throws Exception {
    StringBuffer servicesText = new StringBuffer();
    for (PendingObject pendingObject : pendingDataObjects) {
        String serviceName = autoRegisterExposedServices(pendingObject);
        if (StringUtils.isNotEmpty(serviceName)) {
            if (servicesText.length() > 0) {
                servicesText.append(',');
            }/*from  w  w w  . j  a  v a  2 s  . c om*/
            servicesText.append(serviceName);
        }
    }
    pendingDataObjects.clear();

    if (servicesText.length() > 0) {
        logger.info("Registered ExposedService(via Annotation): [" + servicesText + "]");
    }
}

From source file:com.googlecode.janrain4j.api.engage.EngageServiceImpl.java

public void setAuthProviders(List<String> providers) throws EngageFailureException, ErrorResponeException {
    StringBuffer sb = new StringBuffer();
    for (String provider : providers) {
        if (sb.length() > 0) {
            sb.append(",");
        }/*from   ww  w  . j  av a  2 s .  c o  m*/
        sb.append(provider);
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put(PROVIDERS_PARAM, sb.toString());
    apiCall(SET_AUTH_PROVIDERS_METHOD, params);
}

From source file:com.bstek.dorado.view.output.StylePropertyOutputter.java

@SuppressWarnings("unchecked")
public void output(Object object, OutputContext context) throws Exception {
    JsonBuilder json = context.getJsonBuilder();
    if (object instanceof Map) {
        StringBuffer style = new StringBuffer();
        Map<String, String> map = (Map<String, String>) object;
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String value = entry.getValue();
            if (OutputUtils.isEscapeValue(value)) {
                continue;
            }/*  w  w w.  ja  v a  2 s.  co m*/
            if (style.length() > 0) {
                style.append(';');
            }
            style.append(entry.getKey()).append(':').append(String.valueOf(value));
        }
        json.value(style.toString());
    } else {
        json.value(object);
    }
}

From source file:com.jaxio.celerio.model.support.jpa.JpaEntity.java

private void appendAttribute(StringBuffer ret, String attribute) {
    if (isNotBlank(attribute)) {
        if (ret.length() > 0) {
            ret.append(", ");
        }/*from   w w  w.j av a 2 s.c om*/
        ret.append(attribute);
    }
}

From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java

@Override
public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    jgen.writeStartObject();//ww w . j  a v a 2 s  .  co  m
    jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue());
    jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType());
    OAuth2RefreshToken refreshToken = token.getRefreshToken();
    if (refreshToken != null) {
        jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue());
    }
    Date expiration = token.getExpiration();
    if (expiration != null) {
        long now = System.currentTimeMillis();
        jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000);
    }
    Set<String> scope = token.getScope();
    if (scope != null && !scope.isEmpty()) {
        StringBuffer scopes = new StringBuffer();
        for (String s : scope) {
            Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + "");
            scopes.append(s);
            scopes.append(" ");
        }
        jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1));
    }
    Map<String, Object> additionalInformation = token.getAdditionalInformation();
    for (String key : additionalInformation.keySet()) {
        jgen.writeObjectField(key, additionalInformation.get(key));
    }
    jgen.writeEndObject();
}

From source file:com.callidusrobotics.ui.MessageBox.java

@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void addLine(final String string, final Color foreground, final Color background,
        final boolean preformatted) {
    final List<String> tokens = getMessageTokens(string, preformatted);
    final StringBuffer stringBuffer = new StringBuffer(lineLength);

    // Append the string token-by-token, line-by-line to the end of the messagebuffer
    while (!tokens.isEmpty()) {
        stringBuffer.delete(0, stringBuffer.length());
        stringBuffer.append(tokens.remove(0));

        // The first word to be printed on the line is too long and needs to be hyphenated
        if (stringBuffer.length() > lineLength) {
            tokens.add(0, stringBuffer.substring(lineLength - 1, stringBuffer.length()));
            stringBuffer.delete(lineLength - 1, stringBuffer.length());
            stringBuffer.append('-');
        }//from  w ww . j av  a  2s.  c  o m

        // Continue to append tokens to the linebuffer one-by-one and append enough whitespace to fill the buffer
        while (stringBuffer.length() < lineLength) {
            stringBuffer.append(' ');

            final boolean tokenWillFit = !tokens.isEmpty()
                    && stringBuffer.length() + tokens.get(0).length() <= lineLength;
            if (!preformatted && tokenWillFit) {
                stringBuffer.append(tokens.remove(0));
            }
        }

        lineBuffer.add(new BufferLine(stringBuffer.toString(), foreground, background));

        // Delete the oldest message line
        if (lineBuffer.size() > maxLines) {
            lineBuffer.remove(0);
        }
    }
}

From source file:com.stimulus.archiva.language.LanguageIdentifier.java

public String identify(Reader reader) throws IOException {

    StringBuffer out = new StringBuffer();
    char[] buffer = new char[2048];
    int len = 0;/*from   w w w .  j  a  va2  s .c  om*/

    while (((len = reader.read(buffer)) != -1) && ((analyzeLength == 0) || (out.length() < analyzeLength))) {
        if (analyzeLength != 0) {
            len = Math.min(len, analyzeLength - out.length());
        }
        out.append(buffer, 0, len);
    }

    if (out.length() < MINIMUM_SAMPLE_LENGTH) {
        logger.debug("the sample is too small to reliably detect the language.");
        return null;
    }
    return identify(out);
}

From source file:com.hbc.api.gateway.alizhifu.util.AlipayCallBackValidator.java

public boolean signValidate(HttpServletRequest request) throws UnsupportedEncodingException {
    Map<String, String> parmmap = this.getParameterMap(request);
    Map<String, String> filterMap = this.parmFilter(parmmap);
    String cleanLink = this.createLinkString(filterMap);

    String alisign = request.getParameter("sign");
    String signType = request.getParameter("sign_type");
    if (StringUtils.isBlank(alisign) || StringUtils.isBlank(signType)) {
        return Boolean.FALSE;
    }/*from   w  w  w  .j  a  v  a  2  s. com*/

    if (signType.equalsIgnoreCase(SIGN_TYPE_OF_MD5)) {
        return AliPayMD5.verify(cleanLink, alisign, alipayConfig.securityCode, SIGN_ENCODING);
    } else if (signType.equalsIgnoreCase(SIGN_TYPE_OF_RSA)) {
        StringBuffer spayurl = new StringBuffer();
        for (String keystr : filterMap.keySet()) {
            spayurl = spayurl.append(keystr + "=" + URLDecoder.decode(filterMap.get(keystr), "UTF-8") + "&");
        }
        String dspayurl = spayurl.substring(0, spayurl.length() - 1);
        //mysign = RSA.sign(dspayurl, alipayConfig.privateKey, "UTF-8");
    }
    return Boolean.FALSE;
}