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:com.amazonaws.services.kinesis.aggregators.datastore.DynamoUtils.java

/**
 * Method which examines an table which backs an Aggregator, and returns a
 * string value which represents the list of attributes in the table. This
 * method assumes that all elements in an aggregate table are the same.
 * // w w  w. j a v a 2 s.c  o  m
 * @param dynamoClient Dynamo DB Client to use for connection to Dynamo DB.
 * @param dynamoTable The Table to get the structure of.
 * @return A String representation of the attribute names in the table.
 * @throws Exception
 */
public static String getDynamoTableStructure(AmazonDynamoDB dynamoClient, String dynamoTable) throws Exception {
    List<String> columns = getDictionaryEntry(dynamoClient, dynamoTable);
    StringBuffer sb = new StringBuffer();
    for (String s : columns) {
        sb.append(String.format("%s,", s));
    }
    return String.format("Dynamo Table %s (%s)", sb.toString().substring(0, sb.length() - 1), dynamoTable);
}

From source file:de.uniwue.info6.misc.StringTools.java

/**
 *
 *
 * @param stringBuffer//from   w w  w. jav a  2 s.c o  m
 * @param places
 * @return
 */
public static StringBuffer removeLastCharacters(StringBuffer stringBuffer, int places) {
    return stringBuffer.replace(stringBuffer.length() - places, stringBuffer.length(), "");
}

From source file:azkaban.utils.Utils.java

public static String flattenToString(Collection<?> collection, String delimiter) {
    StringBuffer buffer = new StringBuffer();
    for (Object obj : collection) {
        buffer.append(obj.toString());//  www .  j  a  va2 s.c  o m
        buffer.append(',');
    }

    if (buffer.length() > 0) {
        buffer.setLength(buffer.length() - 1);
    }
    return buffer.toString();
}

From source file:com.vertica.hivestoragehandler.VerticaOutputFormat.java

public static void checkOutputSpecs(VerticaConfiguration vtconfig) throws IOException {
    VerticaRelation vTable = new VerticaRelation(vtconfig.getOutputTableName());
    if (vTable.isNull())
        throw new IOException("Vertica output requires a table name defined by "
                + VerticaConfiguration.OUTPUT_TABLE_NAME_PROP);
    String[] def = vtconfig.getOutputTableDef();
    boolean dropTable = vtconfig.getDropTable();

    Statement stmt = null;//  w  w  w .  j a v  a2 s  . c  o m
    try {
        Connection conn = vtconfig.getConnection(true);
        DatabaseMetaData dbmd = conn.getMetaData();
        ResultSet rs = dbmd.getTables(null, vTable.getSchema(), vTable.getTable(), null);
        boolean tableExists = rs.next();

        stmt = conn.createStatement();

        if (tableExists && dropTable) {
            stmt = conn.createStatement();
            stmt.execute("TRUNCATE TABLE " + vTable.getQualifiedName().toString());
        }

        // create table if it doesn't exist
        if (!tableExists) {
            if (def == null)
                throw new RuntimeException("Table " + vTable.getQualifiedName().toString()
                        + " does not exist and no table definition provided");
            if (!vTable.isDefaultSchema()) {
                stmt.execute("CREATE SCHEMA IF NOT EXISTS " + vTable.getSchema());
            }
            StringBuffer tabledef = new StringBuffer("CREATE TABLE ")
                    .append(vTable.getQualifiedName().toString()).append(" (");
            for (String column : def)
                tabledef.append(column).append(",");
            tabledef.replace(tabledef.length() - 1, tabledef.length(), ")");
            stmt.execute(tabledef.toString());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (stmt != null)
            try {
                stmt.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
    }
}

From source file:com.microsoft.tfs.core.httpclient.HttpState.java

/**
 * Returns a string representation of the cookies.
 *
 * @param cookies/*from   w  ww.  j  av a 2s .  c o  m*/
 *        The cookies
 * @return The string representation.
 */
private static String getCookiesStringRepresentation(final List<Cookie> cookies) {
    final StringBuffer sbResult = new StringBuffer();
    final Iterator<Cookie> iter = cookies.iterator();
    while (iter.hasNext()) {
        final Cookie ck = iter.next();
        if (sbResult.length() > 0) {
            sbResult.append("#");
        }
        sbResult.append(ck.toExternalForm());
    }
    return sbResult.toString();
}

From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.ReportUtils.java

/**
 * Converts a bipartition array into a list of class names. Parameter arrays must have the same
 * length/*  ww w.  j ava2s.  c o  m*/
 * 
 * @param labels
 * @param classNames
 * @return
 */
public static String doubleArrayToClassNames(int[] labels, String[] classNames, Character separatorChar) {
    StringBuffer buffer = new StringBuffer();

    for (int y = 0; y < labels.length; y++) {
        if (labels[y] == 1) {
            buffer.append(classNames[y] + separatorChar);
        }
    }
    String classString;
    try {
        classString = buffer.substring(0, buffer.length() - 1).toString();
    } catch (StringIndexOutOfBoundsException e) {
        classString = "";
    }
    return classString;
}

From source file:com.fantasia.snakerflow.engine.SnakerHelper.java

public static String getNodeJson(List<NodeModel> nodes) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("states: {");
    for (NodeModel node : nodes) {
        buffer.append(node.getName());//from   w w  w .  j a v  a  2 s . c  o m
        buffer.append(getBase(node));
        buffer.append(getLayout(node));
        buffer.append(getProperty(node));
        buffer.append(",");
    }
    buffer.deleteCharAt(buffer.length() - 1);
    buffer.append("},");
    return buffer.toString();
}

From source file:com.thalesgroup.hudson.plugins.klocwork.util.KloMetricUtil.java

public static String getMessageSelectedSeverties(KloConfig kloConfig) {
    StringBuffer sb = new StringBuffer();

    if (kloConfig.getConfigSeverityEvaluation().isAllSeverities()) {
        sb.append("with all severities");
        return sb.toString();
    }//from   w  ww.  ja va2s.com

    if (kloConfig.getConfigSeverityEvaluation().isHighSeverity()) {
        sb.append(" and ");
        sb.append("severity 'high severity'");
    }

    if (kloConfig.getConfigSeverityEvaluation().isLowSeverity()) {
        sb.append(" and ");
        sb.append("severity 'low severity'");
    }

    if (sb.length() != 0)
        sb.delete(0, 5);

    return sb.toString();
}

From source file:com.josephblough.sbt.transport.SbaTransport.java

public static List<LoanAndGrantData> getLoansAndGrantsDataBySpecialties(final List<String> specialties) {
    final StringBuffer parameters = new StringBuffer();
    for (String speciality : specialties) {
        if (parameters.length() > 0) {
            parameters.append("-");
        }/* w w  w  . ja v a2 s.  c o m*/
        parameters.append(formatForUrl(speciality));
    }
    final String url = LOANS_AND_GRANTS_BASE_URL + "nil/for_profit/nil/" + parameters.toString() + ".json";
    return getLoansAndGrantsData(url);
}

From source file:Main.java

/**
 * Looks for a text child node and returns its value.
 *
 * @param tag - XML element/*ww  w  .  j av  a 2 s.c  o  m*/
 * @return - the text String of the tag
 */
public static String getText(final Element tag) {
    if (tag == null)
        return null;

    NodeList lst = tag.getChildNodes();
    StringBuffer buf = new StringBuffer();

    for (int Index = 0, Cnt = lst.getLength(); Index < Cnt; Index++) {
        if (lst.item(Index).getNodeType() == Node.ENTITY_REFERENCE_NODE) {
            buf.append(lst.item(Index).getChildNodes().item(0).getNodeValue());
        }
        if ((lst.item(Index).getNodeType() == Node.TEXT_NODE)
                || (lst.item(Index).getNodeType() == Node.CDATA_SECTION_NODE)) {
            buf.append(lst.item(Index).getNodeValue());
        }
    }

    if (buf.length() == 0)
        return null;
    else
        return buf.toString();
}