Package org.apache.commons.lang.text

Examples of org.apache.commons.lang.text.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 $


   * @throws AmbariException
   */
  public BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName)
    throws AmbariException {

    StrBuilder sb = new StrBuilder();
    sb.append(DEFAULT_API_PATH)
      .append("/clusters/")
      .append(clusterName)
      .append("/requests/")
      .append(requestId);

    return performApiGetRequest(sb.toString(), true);

  }
View Full Code Here


            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

     * @throws UnsupportedEncodingException
     */
    private String getStringFromResultSet(ResultSet rs) throws SQLException, UnsupportedEncodingException {
        ResultSetMetaData meta = rs.getMetaData();

        StrBuilder sb = new StrBuilder();
       
        int numColumns = meta.getColumnCount();
        for (int i = 1; i <= numColumns; i++) {
            sb.append(meta.getColumnName(i));
            if (i==numColumns){
                sb.append('\n');
            } else {
                sb.append('\t');
            }
        }

        JMeterVariables jmvars = null;
        String varnames[] = getVariableNames().split(COMMA);
        if (varnames.length > 0){
            jmvars = getThreadContext().getVariables();
        }
        int j = 0;
        while (rs.next()) {
            j++;
            for (int i = 1; i <= numColumns; i++) {
                Object o = rs.getObject(i);
                if (o instanceof byte[]) {
                    o = new String((byte[]) o, ENCODING);
                }
                sb.append(o);
                if (i==numColumns){
                    sb.append('\n');
                } else {
                    sb.append('\t');
                }
                if (jmvars != null && i <= varnames.length) {
                    String name = varnames[i - 1].trim();
                    if (name.length()>0){ // Save the value in the variable if present
                        jmvars.put(name+UNDERSCORE+j, o == null ? null : o.toString());
                    }
                }
            }
        }
        // Remove any additional values from previous sample
        for(int i=0; i < varnames.length; i++){
            String name = varnames[i].trim();
            if (name.length()>0 && jmvars != null){
                final String varCount = name+"_#"; // $NON-NLS-1$
                // Get the previous count
                String prevCount = jmvars.get(varCount);
                if (prevCount != null){
                    int prev = Integer.parseInt(prevCount);
                    for (int n=j+1; n <= prev; n++ ){
                        jmvars.remove(name+UNDERSCORE+n);
                    }
                }
                jmvars.put(varCount, Integer.toString(j)); // save the current count
            }
        }
       
        return sb.toString();
    }
View Full Code Here

    public String getQuery() {
        return query;
    }

    public String toString() {
        StrBuilder sb = new StrBuilder(80);
        sb.append("["); // $NON-NLS-1$
        sb.append(getQueryType());
        sb.append("] "); // $NON-NLS-1$
        sb.append(getQuery());
        sb.append("\n");
        sb.append(getQueryArguments());
        sb.append("\n");
        sb.append(getQueryArgumentsTypes());
        return sb.toString();
    }
View Full Code Here

        res.sampleEnd();
        return res;
    }

    private String resultSetsToString(PreparedStatement pstmt, boolean result, int[] out) throws SQLException, UnsupportedEncodingException {
        StrBuilder sb = new StrBuilder();
        int updateCount = 0;
        if (!result) {
            updateCount = pstmt.getUpdateCount();
        }
        do {
            if (result) {
                ResultSet rs = null;
                try {
                    rs = pstmt.getResultSet();
                    sb.append(getStringFromResultSet(rs)).append("\n"); // $NON-NLS-1$
                } finally {
                    close(rs);
                }
            } else {
                sb.append(updateCount).append(" updates.\n");
            }
            result = pstmt.getMoreResults();
            if (!result) {
                updateCount = pstmt.getUpdateCount();
            }
        } while (result || (updateCount != -1));
        if (out!=null && pstmt instanceof CallableStatement){
            CallableStatement cs = (CallableStatement) pstmt;
            sb.append("Output variables by position:\n");
            for(int i=0; i < out.length; i++){
                if (out[i]!=java.sql.Types.NULL){
                    sb.append("[");
                    sb.append(i+1);
                    sb.append("] ");
                    sb.append(cs.getObject(i+1));
                    sb.append("\n");
                }
            }
        }
        return sb.toString();
    }
View Full Code Here

            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

     * 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());
        String port = getPort();
        if (port.length() > 0){
            sb.append(':');
            sb.append(port);
        }
        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

    res.sampleEnd();
    return res;
  }

  private String resultSetsToString(PreparedStatement pstmt, boolean result, int[] out) throws SQLException {
    StrBuilder sb = new StrBuilder();
    sb.append("\n"); // $NON-NLS-1$
    int updateCount = 0;
    if (!result) {
      updateCount = pstmt.getUpdateCount();
    }
    do {
      if (result) {
        ResultSet rs = null;
        try {
          rs = pstmt.getResultSet();
          Data data = getDataFromResultSet(rs);
          sb.append(data.toString()).append("\n"); // $NON-NLS-1$
        } finally {
          close(rs);
        }
      } else {
        sb.append(updateCount).append(" updates.\n");
      }
      result = pstmt.getMoreResults();
      if (!result) {
        updateCount = pstmt.getUpdateCount();
      }
    } while (result || (updateCount != -1));
    if (out!=null && pstmt instanceof CallableStatement){
      CallableStatement cs = (CallableStatement) pstmt;
      sb.append("Output variables by position:\n");
      for(int i=0; i < out.length; i++){
        if (out[i]!=java.sql.Types.NULL){
          sb.append("[");
          sb.append(i+1);
          sb.append("] ");
          sb.append(cs.getObject(i+1));
          sb.append("\n");
        }
      }
    }
    return sb.toString();
  }
View Full Code Here

  public String getQuery() {
    return query;
  }

  public String toString() {
        StrBuilder sb = new StrBuilder(80);
        sb.append("["); // $NON-NLS-1$
        sb.append(getQueryType());
        sb.append("] "); // $NON-NLS-1$
        sb.append(getQuery());
    return sb.toString();
  }
View Full Code Here

   * 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

TOP

Related Classes of org.apache.commons.lang.text.StrBuilder

Copyright © 2018 www.massapicom. 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.