Example usage for java.lang StringBuilder delete

List of usage examples for java.lang StringBuilder delete

Introduction

In this page you can find the example usage for java.lang StringBuilder delete.

Prototype

@Override
public StringBuilder delete(int start, int end) 

Source Link

Usage

From source file:org.apache.phoenix.util.PhoenixMRJobUtil.java

public static String getJobsInformationFromRM(String rmhost, int rmport, Map<String, String> urlParams)
        throws MalformedURLException, ProtocolException, UnsupportedEncodingException, IOException {
    HttpURLConnection con = null;
    String response = null;/*from w ww.j a  v a  2s  .  c  o  m*/
    String url = null;

    try {
        StringBuilder urlBuilder = new StringBuilder();

        urlBuilder.append(RM_HTTP_SCHEME + "://").append(rmhost).append(":").append(rmport)
                .append(RM_APPS_GET_ENDPOINT);

        if (urlParams != null && urlParams.size() != 0) {
            urlBuilder.append("?");
            for (String key : urlParams.keySet()) {
                urlBuilder.append(key + "=" + urlParams.get(key) + "&");
            }
            urlBuilder.delete(urlBuilder.length() - 1, urlBuilder.length());
        }

        url = urlBuilder.toString();
        LOG.info("Attempt to get running/submitted jobs information from RM URL = " + url);

        URL obj = new URL(url);
        con = (HttpURLConnection) obj.openConnection();
        con.setInstanceFollowRedirects(true);
        con.setRequestMethod("GET");

        con.setConnectTimeout(RM_CONNECT_TIMEOUT_MILLIS);
        con.setReadTimeout(RM_READ_TIMEOUT_MILLIS);

        response = getTextContent(con.getInputStream());
    } finally {
        if (con != null)
            con.disconnect();
    }

    LOG.info("Result of attempt to get running/submitted jobs from RM - URL=" + url + ",ResponseCode="
            + con.getResponseCode() + ",Response=" + response);

    return response;
}

From source file:com.seleniumtests.util.StringUtility.java

public static String constructParameterString(final Object[] parameters) {
    StringBuilder sbParam = new StringBuilder();

    if (parameters != null) {
        for (int i = 0; i < parameters.length; i++) {
            if (parameters[i] == null) {
                sbParam.append("null, ");
            } else if (parameters[i] instanceof java.lang.String) {
                sbParam.append("\"").append(parameters[i]).append("\", ");
            } else {
                sbParam.append(parameters[i]).append(", ");
            }//from  www .  ja  v  a2s .c o m
        }
    }

    if (sbParam.length() > 0) {
        sbParam.delete(sbParam.length() - 2, sbParam.length() - 1);
    }

    return sbParam.toString();
}

From source file:com.googlecode.promnetpp.main.Main.java

private static void preprocessSourceCode() {
    StringBuilder sourceCodeAsBuilder = new StringBuilder(sourceCode);
    String commentRegex = "/[*].*?[*]/";
    Pattern commentPattern = Pattern.compile(commentRegex, Pattern.DOTALL);
    Matcher commentMatcher = commentPattern.matcher(sourceCodeAsBuilder);
    while (commentMatcher.find()) {
        String comment = commentMatcher.group().replace("/*", "").replace("*/", "").trim();
        boolean isAnnotatedComment = comment.startsWith("@");
        if (!isAnnotatedComment) {
            //Remove the comment and reset the matcher
            sourceCodeAsBuilder.delete(commentMatcher.start(), commentMatcher.end());
            commentMatcher = commentPattern.matcher(sourceCodeAsBuilder);
        }//from   w ww.  j  a  v  a2 s .c  o m
    }
    sourceCode = sourceCodeAsBuilder.toString();
}

From source file:br.com.carlosrafaelgn.fplay.list.RadioStationList.java

private static String readStringIfPossible(XmlPullParser parser, StringBuilder sb) throws Throwable {
    sb.delete(0, sb.length());
    switch (parser.getEventType()) {
    case XmlPullParser.COMMENT:
        break;/* ww  w  .j  a v  a2  s  . c  om*/
    case XmlPullParser.ENTITY_REF:
        break;
    case XmlPullParser.IGNORABLE_WHITESPACE:
        sb.append(' ');
        break;
    case XmlPullParser.PROCESSING_INSTRUCTION:
    case XmlPullParser.TEXT:
        if (parser.isWhitespace())
            sb.append(' ');
        else
            sb.append(parser.getText());
        break;
    default:
        return null;
    }
    for (;;) {
        switch (parser.nextToken()) {
        case XmlPullParser.COMMENT:
            break;
        case XmlPullParser.ENTITY_REF:
            break;
        case XmlPullParser.IGNORABLE_WHITESPACE:
            sb.append(' ');
            break;
        case XmlPullParser.PROCESSING_INSTRUCTION:
        case XmlPullParser.TEXT:
            if (parser.isWhitespace())
                sb.append(' ');
            else
                sb.append(parser.getText());
            break;
        default:
            return sb.toString();
        }
    }
}

From source file:com.impetus.client.couchdb.CouchDBUtils.java

/**
 * Creates the view.//from w  ww.j a va  2  s .  c  o m
 * 
 * @param views
 *            the views
 * @param columnName
 *            the column name
 * @param columns
 *            the columns
 */
static void createView(Map<String, MapReduce> views, String columnName, List<String> columns) {
    Iterator<String> iterator = columns.iterator();

    MapReduce mapr = new MapReduce();
    StringBuilder mapBuilder = new StringBuilder();
    StringBuilder ifBuilder = new StringBuilder("function(doc){if(");
    StringBuilder emitFunction = new StringBuilder("{emit(");
    if (columns != null && columns.size() > 1) {
        emitFunction.append("[");
    }
    while (iterator.hasNext()) {
        String nextToken = iterator.next();
        ifBuilder.append("doc." + nextToken);
        ifBuilder.append(" && ");
        emitFunction.append("doc." + nextToken);
        emitFunction.append(",");
    }
    ifBuilder.delete(ifBuilder.toString().lastIndexOf(" && "), ifBuilder.toString().lastIndexOf(" && ") + 3);
    emitFunction.deleteCharAt(emitFunction.toString().lastIndexOf(","));

    ifBuilder.append(")");
    if (columns != null && columns.size() > 1) {
        emitFunction.append("]");
    }
    emitFunction.append(", doc)}}");

    mapBuilder.append(ifBuilder.toString()).append(emitFunction.toString());

    mapr.setMap(mapBuilder.toString());
    views.put(columnName, mapr);
}

From source file:ezbake.deployer.impl.Files.java

public static File relativize(File base, File target) {
    String[] baseComponents;/*from  www  .j av a  2  s.c  om*/
    String[] targetComponents;
    try {
        baseComponents = base.getCanonicalPath().split(Pattern.quote(File.separator));
        targetComponents = target.getCanonicalPath().split(Pattern.quote(File.separator));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    // skip common components
    int index = 0;
    for (; index < targetComponents.length && index < baseComponents.length; ++index) {
        if (!targetComponents[index].equals(baseComponents[index]))
            break;
    }

    StringBuilder result = new StringBuilder();
    if (index != baseComponents.length) {
        // backtrack to base directory
        for (int i = index; i < baseComponents.length; ++i)
            result.append("..").append(File.separator);
    }
    for (; index < targetComponents.length; ++index)
        result.append(targetComponents[index]).append(File.separator);
    if (!target.getPath().endsWith("/") && !target.getPath().endsWith("\\")) {
        // remove final path separator
        result.delete(result.length() - File.separator.length(), result.length());
    }
    return new File(result.toString());
}

From source file:org.apache.sqoop.TestExportUsingProcedure.java

private static void insertFunction(int id, String msg, SetExtraArgs setExtraArgs) throws SQLException {
    instanceForProcedure.functionCalls += 1;
    Connection con = instanceForProcedure.getConnection();

    StringBuilder sql = new StringBuilder("insert into ");
    sql.append(instanceForProcedure.getTableName());
    sql.append("(id, msg");
    for (int i = 0; i < instanceForProcedure.names.length; ++i) {
        sql.append(",");
        sql.append(instanceForProcedure.names[i]);
    }//ww  w. ja  v a 2 s.c om
    sql.append(") values (");
    for (int i = 0; i < instanceForProcedure.names.length + 2; ++i) {
        sql.append("?,");
    }
    // Remove last ,
    sql = sql.delete(sql.length() - 1, sql.length());
    sql.append(")");

    PreparedStatement statement = con.prepareStatement(sql.toString());
    try {
        statement.setInt(1, id);
        statement.setString(2, msg);
        setExtraArgs.set(statement);
        statement.execute();
        con.commit();
    } finally {
        statement.close();
    }
}

From source file:net.radai.beanz.util.ReflectionUtil.java

public static String prettyPrint(Method method) {
    StringBuilder sb = new StringBuilder();
    Class<?> declaredOn = method.getDeclaringClass();
    sb.append(prettyPrint(declaredOn)).append(".").append(method.getName()).append("(");
    if (method.getParameterCount() > 0) {
        for (Type paramType : method.getGenericParameterTypes()) {
            sb.append(prettyPrint(paramType)).append(", ");
        }/*from w ww  .j  a v a2s.c om*/
        sb.delete(sb.length() - 2, sb.length());
    }
    sb.append(")");
    return sb.toString();
}

From source file:com.mirth.connect.server.util.DatabaseUtil.java

public static List<String> joinSqlStatements(Collection<String> scripts) {
    List<String> scriptList = new ArrayList<String>();

    for (String script : scripts) {
        script = script.trim();/*from  w  ww  .j  a  v  a  2 s . c o  m*/
        StringBuilder sb = new StringBuilder();
        boolean blankLine = false;
        Scanner scanner = new Scanner(script);

        while (scanner.hasNextLine()) {
            String temp = scanner.nextLine();

            if (temp.trim().length() > 0) {
                sb.append(temp + " ");
            } else {
                blankLine = true;
            }

            if (blankLine || !scanner.hasNextLine()) {
                scriptList.add(sb.toString().trim());
                blankLine = false;
                sb.delete(0, sb.length());
            }
        }
    }

    return scriptList;
}

From source file:com.uber.hoodie.hive.client.SchemaUtil.java

/**
 * Return a 'struct' Hive schema from a list of Parquet fields
 *
 * @param parquetFields : list of parquet fields
 * @return : Equivalent 'struct' Hive schema
 *///ww w  . j a va 2 s.c om
private static String createHiveStruct(List<Type> parquetFields) {
    StringBuilder struct = new StringBuilder();
    struct.append("STRUCT< ");
    for (Type field : parquetFields) {
        //TODO: struct field name is only translated to support special char($)
        //We will need to extend it to other collection type
        struct.append(hiveCompatibleFieldName(field.getName(), true)).append(" : ");
        struct.append(convertField(field)).append(", ");
    }
    struct.delete(struct.length() - 2, struct.length()); // Remove the last
    // ", "
    struct.append(">");
    String finalStr = struct.toString();
    // Struct cannot have - in them. userstore_udr_entities has uuid in struct. This breaks the schema.
    // HDrone sync should not fail because of this.
    finalStr = finalStr.replaceAll("-", "_");
    return finalStr;
}