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());
            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

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

            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

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

         * @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

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

            return query;
        }

        @Override
        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

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

            log.debug("Saving " + s.getSampleLabel() + " in " + fileName);
            s.setResultFileName(fileName);// Associate sample with file name
            String variable = getVariableName();
            if (variable.length()>0){
                if (num > 0) {
                    StrBuilder sb = new StrBuilder(variable);
                    sb.append(num);
                    variable=sb.toString();
                }
                JMeterContextService.getContext().getVariables().put(variable, fileName);
            }
            File out = new File(fileName);
            FileOutputStream pw = null;
    View Full Code Here

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

         * @return fileName composed of fixed prefix, a number, and a suffix derived
         *         from the contentType e.g. Content-Type:
         *         text/html;charset=ISO-8859-1
         */
        private String makeFileName(String contentType, boolean skipAutoNumber, boolean skipSuffix) {
            StrBuilder sb = new StrBuilder(getFilename());
            if (!skipAutoNumber){
                sb.append(nextNumber());
            }
            if (!skipSuffix){
                sb.append('.');
                if (contentType != null) {
                    int i = contentType.indexOf("/"); // $NON-NLS-1$
                    if (i != -1) {
                        int j = contentType.indexOf(";"); // $NON-NLS-1$
                        if (j != -1) {
                            sb.append(contentType.substring(i + 1, j));
                        } else {
                            sb.append(contentType.substring(i + 1));
                        }
                    } else {
                        sb.append("unknown");
                    }
                } else {
                    sb.append("unknown");
                }
            }
            return sb.toString();
        }
    View Full Code Here

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

            }
            if (str == null) {
                return;
            }
            int sz = str.length();
            StrBuilder unicode = new StrBuilder(4);
            boolean hadSlash = false;
            boolean inUnicode = false;
            for (int i = 0; i < sz; i++) {
                char ch = str.charAt(i);
                if (inUnicode) {
                    // if in unicode, then we're reading unicode
                    // values in somehow
                    unicode.append(ch);
                    if (unicode.length() == 4) {
                        // unicode now contains the four hex digits
                        // which represents our unicode character
                        try {
                            int value = Integer.parseInt(unicode.toString(), 16);
                            out.write((char) value);
                            unicode.setLength(0);
                            inUnicode = false;
                            hadSlash = false;
                        } catch (NumberFormatException nfe) {
                            throw new NestableRuntimeException("Unable to parse unicode value: " + unicode, nfe);
                        }
    View Full Code Here

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

            }
            if (className.length() == 0) {
                return StringUtils.EMPTY;
            }

            StrBuilder arrayPrefix = new StrBuilder();

            // Handle array encoding
            if (className.startsWith("[")) {
                while (className.charAt(0) == '[') {
                    className = className.substring(1);
                    arrayPrefix.append("[]");
                }
                // Strip Object type encoding
                if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';') {
                    className = className.substring(1, className.length() - 1);
                }
    View Full Code Here

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

        private static String toCanonicalName(String className) {
            className = StringUtils.deleteWhitespace(className);
            if (className == null) {
                throw new NullArgumentException("className");
            } else if (className.endsWith("[]")) {
                StrBuilder classNameBuffer = new StrBuilder();
                while (className.endsWith("[]")) {
                    className = className.substring(0, className.length() - 2);
                    classNameBuffer.append("[");
                }
                String abbreviation = (String) abbreviationMap.get(className);
                if (abbreviation != null) {
                    classNameBuffer.append(abbreviation);
                } else {
                    classNameBuffer.append("L").append(className).append(";");
                }
                className = classNameBuffer.toString();
            }
            return className;
        }
    View Full Code Here

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

                        if (className.length() > 0) {
                            className = (String) reverseAbbreviationMap.get(
                                className.substring(0, 1));
                        }
                    }
                    StrBuilder canonicalClassNameBuffer = new StrBuilder(className);
                    for (int i = 0; i < dim; i++) {
                        canonicalClassNameBuffer.append("[]");
                    }
                    return canonicalClassNameBuffer.toString();
                }
            }
        }
    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.