Examples of StrBuilder

The aim has been to provide an API that mimics very closely what StringBuffer provides, but with additional methods. It should be noted that some edge cases, with invalid indices or null input, have been altered - see individual methods. The biggest of these changes is that by default, null will not output the text 'null'. This can be controlled by a property, {@link #setNullText(String)}.

Prior to 3.0, this class implemented Cloneable but did not implement the clone method so could not be used. From 3.0 onwards it no longer implements the interface. @author Apache Software Foundation @since 2.2 @version $Id: StrBuilder.java 1057349 2011-01-10 20:40:49Z niallp $

  • org.apache.commons.lang3.text.StrBuilder
    Builds a string from constituent parts providing a more flexible and powerful API than StringBuffer.

    The main differences from StringBuffer/StringBuilder are:

  • Views
  • The aim has been to provide an API that mimics very closely what StringBuffer provides, but with additional methods. It should be noted that some edge cases, with invalid indices or null input, have been altered - see individual methods. The biggest of these changes is that by default, null will not output the text 'null'. This can be controlled by a property, {@link #setNullText(String)}.

    Prior to 3.0, this class implemented Cloneable but did not implement the clone method so could not be used. From 3.0 onwards it no longer implements the interface. @since 2.2 @version $Id: StrBuilder.java 1153484 2011-08-03 13:39:42Z ggregory $


    Examples of org.apache.commons.lang.text.StrBuilder

       * ftp://ftp.nowhere.com/pub/README.txt
       *
       * @return a formatted string label describing this sampler
       */
      public String getLabel() {
          StrBuilder sb = new StrBuilder();
          sb.setNullText("null");// $NON-NLS-1$
          sb.append("ftp://");// $NON-NLS-1$
          sb.append(getServer());
          sb.append("/");// $NON-NLS-1$
          sb.append(getRemoteFilename());
          sb.append(isBinaryMode() ? " (Binary) " : " (Ascii) ");// $NON-NLS-1$ $NON-NLS-2$
        sb.append(isUpload() ? " <- " : " -> "); // $NON-NLS-1$ $NON-NLS-2$
        sb.append(getLocalFilename());
        return sb.toString();
      }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

         *
         * @param ba input binary byte array
         * @return hex representation of binary input
         */
        public static String baToHexString(byte ba[]) {
            StrBuilder sb = new StrBuilder(ba.length*2);
            for (int i = 0; i < ba.length; i++) {
                int j = ba[i] & 0xff;
                if (j < 16) {
                    sb.append("0"); // $NON-NLS-1$ add zero padding
                }
                sb.append(Integer.toHexString(j));
            }
            return sb.toString();
        }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

              return prog.getTimeFieldAsString(fieldType);
            }
          }
        }

        StrBuilder buffer = new StrBuilder();
        for (ProgramFieldType fieldType : fieldArr) {
          // Get the field value as String
          String value = null;
          if (fieldType != null) {
            if (fieldType.getFormat() == ProgramFieldType.TEXT_FORMAT) {
              value = prog.getTextField(fieldType);
            }
            else if (fieldType.getFormat() == ProgramFieldType.INT_FORMAT) {
              value = prog.getIntFieldAsString(fieldType);
            }
            else if (fieldType.getFormat() == ProgramFieldType.TIME_FORMAT) {
              if (fieldType == ProgramFieldType.START_TIME_TYPE) {
                value = prog.getTimeString();
              }
              else if (fieldType == ProgramFieldType.END_TIME_TYPE) {
                value = prog.getEndTimeString();
              }
              else {
                value = prog.getTimeFieldAsString(fieldType);
              }
            }
          }

          if (value != null) {
            buffer.append(value).append(' ');
          }
        }

        /* Remove special characters */

        if(mReplaceSpCh) {
          buffer.replaceAll("\\p{Punct}", ";");
        }

        // remove line breaks
        buffer.replaceAll('\n', ' ');
        return buffer.trim().toString();
      }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

                getLog().error(msg);
                throw new VelocityException(msg);
            }

            /* now just create the VM call, and use evaluate */
            StrBuilder template = new StrBuilder("#");
            template.append(vmName);
            template.append("(");
            for( int i = 0; i < params.length; i++)
            {
                template.append(" $");
                template.append(params[i]);
            }
            template.append(" )");

            return evaluate(context, writer, logTag, template.toString());
        }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

                getLog().error(msg);
                throw new VelocityException(msg);
            }

            /* now just create the VM call, and use evaluate */
            StrBuilder template = new StrBuilder("#");
            template.append(vmName);
            template.append("(");
            for( int i = 0; i < params.length; i++)
            {
                template.append(" $");
                template.append(params[i]);
            }
            template.append(" )");

            return evaluate(context, writer, logTag, template.toString());
        }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

                getLog().error(msg);
                throw new VelocityException(msg);
            }

            /* now just create the VM call, and use evaluate */
            StrBuilder template = new StrBuilder("#");
            template.append(vmName);
            template.append("(");
            for( int i = 0; i < params.length; i++)
            {
                template.append(" $");
                template.append(params[i]);
            }
            template.append(" )");

            return evaluate(context, writer, logTag, template.toString());
        }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

        if (description != null) {
          objectParts.add("\"detailed_message\":\"" + EscapeUtil.jsonEscape(description)
              + "\"");
        }
        return new StrBuilder("{").appendWithSeparators(objectParts, ",").append("}").toString();
      }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

       */
      public static CharSequence renderJsonResponse(
          DataSourceParameters dsParams,
          ResponseStatus responseStatus,
          DataTable data) {
        StrBuilder sb = new StrBuilder();
        boolean isJsonp = dsParams.getOutputType() == OutputType.JSONP;
        if (isJsonp) {
          sb.append(dsParams.getResponseHandler()).append("(");
        }
        sb.append("{\"version\":\"0.6\"");

        // If no reqId found in the request, do not return reqId in the response.
        String requestId = dsParams.getRequestId();
        if (requestId != null) {
          sb.append(",\"reqId\":\"").append(EscapeUtil.jsonEscape(requestId)).append("\"");
        }

        // Check signature.
        String previousSignature = dsParams.getSignature();
        if (responseStatus == null) {
          if (!StringUtils.isEmpty(previousSignature) && (data != null)
              && (JsonRenderer.getSignature(data).equals(previousSignature))) {
            responseStatus = new ResponseStatus(StatusType.ERROR, ReasonType.NOT_MODIFIED, null);
          } else {
            responseStatus = new ResponseStatus(StatusType.OK, null, null);
          }
        }

        StatusType statusType = responseStatus.getStatusType();
        sb.append(",\"status\":\"").append(statusType.lowerCaseString()).append("\"");

        // There are reason and messages if the status is WARNING/ERROR.
        if (statusType != StatusType.OK) {
          // Status is warning or error.
          if (statusType == StatusType.WARNING) {
            List<Warning> warnings = data.getWarnings();
            List<String> warningJsonStrings = Lists.newArrayList();
            if (warnings != null) {
              for (Warning warning : warnings) {
                warningJsonStrings.add(getFaultString(warning.getReasonType(), warning.getMessage()));
              }
            }
            sb.append(",\"warnings\":[").appendWithSeparators(warningJsonStrings, ",").append("]");

          } else { // Status is error.
            sb.append(",\"errors\":[");
            sb.append(getFaultString(responseStatus.getReasonType(), responseStatus.getDescription()));
            sb.append("]");
          }
        }
       
        if ((statusType != StatusType.ERROR) && (data != null)) {
          // MessageType OK or WARNING,
          // so need to attach a data table (and a signature).
          sb.append(",\"sig\":\"").append(JsonRenderer.getSignature(data)).append("\"");
          sb.append(",\"table\":").append(JsonRenderer.renderDataTable(data, true, true, isJsonp));
        }
       
        sb.append("}");
        if (isJsonp) {
          sb.append(");");
        }
       
        return sb.toString();
      }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

          for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            customPropertiesStrings.add("\""
                + EscapeUtil.jsonEscape(entry.getKey()) + "\":\""
                + EscapeUtil.jsonEscape(entry.getValue()) + "\"");
          }
          customPropertiesString = new StrBuilder("{")
              .appendWithSeparators(customPropertiesStrings, ",").append("}").toString();
        }
        return customPropertiesString;
      }
    View Full Code Here

    Examples of org.apache.commons.lang.text.StrBuilder

          throws DataSourceException {
        Connection con = getDatabaseConnection(databaseDescription);
        String tableName = databaseDescription.getTableName();

        // Build the sql query.
        StrBuilder queryStringBuilder = new StrBuilder();
        buildSqlQuery(query, queryStringBuilder, tableName);
        List<String> columnIdsList = null;
        if (query.hasSelection()) {
          columnIdsList = getColumnIdsList(query.getSelection());
        }
        Statement stmt = null;
        try {
          // Execute the sql query.
          stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery(queryStringBuilder.toString());

          DataTable table = buildColumns(rs, columnIdsList);

          // Fill the data in the data table.
          buildRows(table, rs);
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.