Example usage for java.lang StringBuilder indexOf

List of usage examples for java.lang StringBuilder indexOf

Introduction

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

Prototype

@Override
    public int indexOf(String str) 

Source Link

Usage

From source file:org.openmrs.contrib.databaseexporter.util.DbUtil.java

public static StringBuilder addConstraintToQuery(StringBuilder query, String constraint) {
    query.append(query.indexOf(" where") == -1 ? " where " : " and ").append(constraint);
    return query;
}

From source file:massbank.svn.MSDBUpdateUtil.java

/**
 *
 *///from  w  ww  .j  a  va  2s  .c  o m
public static boolean updateSubStructData(String serverUrl) {
    boolean ret = true;
    String cgiUrl = serverUrl + "cgi-bin/GenSubstructure.cgi";
    try {
        URL url = new URL(cgiUrl);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setConnectTimeout(10 * 1000);
        con.setReadTimeout(60 * 1000);
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line = "";
        StringBuilder res = new StringBuilder();
        while ((line = in.readLine()) != null) {
            res.append(line);
        }
        if (res.indexOf("OK") == -1) {
            ret = false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        ret = false;
    }
    return ret;
}

From source file:com.indoqa.lang.util.URLStringUtils.java

public static String replaceParameter(String path, String parameterName, Object parameterValue) {
    StringBuilder stringBuilder = new StringBuilder(path);
    String searchString = "{" + parameterName + "}";

    while (true) {
        int index = stringBuilder.indexOf(searchString);
        if (index == -1) {
            break;
        }//from   w  ww.  java 2  s .  com

        stringBuilder.replace(index, index + searchString.length(), String.valueOf(parameterValue));
    }

    return stringBuilder.toString();
}

From source file:com.googlecode.mashups.services.generic.impl.FeedReaderImpl.java

private static Object getJSONData(String arrayName, StringBuilder content) throws Exception {
    if (arrayName.equalsIgnoreCase(NONE)) {

        // This means it is not an array, it is a simple dummy object ...
        if (content.indexOf("[") == -1 && content.indexOf("{") == 0) {
            //System.out.println("content: " + content);
            return new JSONObject(content.toString());
        }/*w  ww  .j a  va 2 s  .  c o m*/

        return new JSONArray(content.toString());
    }

    String searchFor = "\"" + arrayName + "\":[";

    int arrayStartIndex = content.indexOf(searchFor);
    int arrayEndIndex = 0;

    if (arrayStartIndex <= -1) {
        return new JSONArray();
    }

    // TODO optimize.
    int balance = 0;

    for (int i = (arrayStartIndex + searchFor.length()); i < content.length(); ++i) {
        char streamChar = content.charAt(i);

        if (streamChar == '[') {
            ++balance;
        } else if (streamChar == ']') {
            if (balance == 0) {
                arrayEndIndex = i + 1;
                break;
            }

            --balance;
        }
    }

    String arrayContent = "{" + content.substring(arrayStartIndex, arrayEndIndex) + "}";

    // create the JSON array.
    JSONObject json = new JSONObject(arrayContent);

    return json.getJSONArray(arrayName);
}

From source file:emily.util.YTUtil.java

/**
 * @param videocode youtubecode//ww  w .  j  a  va  2s. c o m
 * @return whats in the <title> tag on a youtube page
 */
public static String getTitleFromPage(String videocode) {
    String ret = "";
    try {
        URL loginurl = new URL("https://www.youtube.com/watch?v=" + videocode);
        URLConnection yc = loginurl.openConnection();
        yc.setConnectTimeout(10 * 1000);
        BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
        StringBuilder input = new StringBuilder();
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            input.append(inputLine);
        in.close();
        int start = input.indexOf("<title>");
        int end = input.indexOf("</title>");
        ret = input.substring(start + 7, end - 10);
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
    }
    return StringEscapeUtils.unescapeHtml4(ret);
}

From source file:org.apache.lucene.search.SearchUtil.java

public static String removeTitle(String contents, String title) {
    if (contents.indexOf("$TITLE_START$") != -1 && contents.indexOf("$TITLE_END$") != -1) {
        StringBuilder sb = new StringBuilder(contents);
        int start = sb.indexOf("$TITLE_START$");
        int end = sb.indexOf("$TITLE_END$");
        String tmp = sb.replace(start, end + "$TITLE_END$".length(), "").toString();
        return StringUtils.removeStart(tmp, title);
    } else {//  ww w .  jav a  2s.  c  o m
        return contents;
    }
}

From source file:dhr.uploadtomicrobit.FirmwareGenerator.java

/**
* Utility method to replace the string from StringBuilder.
* @param sb          the StringBuilder object.
* @param toReplace   the String that should be replaced.
* @param replacement the String that has to be replaced by.
* 
*///from w  ww  . j a  v  a 2s .  com
public static void replaceString(StringBuilder sb, String toReplace, String replacement) {

    System.out.println("Pattern : " + toReplace + " Len: " + toReplace.length());

    int index = sb.indexOf(toReplace);

    System.out.println("Index of pattern: " + index);

    if (index <= 0) {
        System.out.println("Failed to see correct replacement pattern in firmware file");
        sb.replace(0, 6, "Invalid");
        return;
    }
    int end = index + toReplace.length();

    System.out.println("Index of pattern: " + index);
    System.out.println("End of pattern: " + end);
    System.out.println("New Pattern : " + replacement);

    sb.replace(index, end, replacement);

    //String tail = new String(sb.substring(end));   // tail conmponent

}

From source file:fr.irit.sparql.Proxy.SparqlProxy.java

public static void replaceAll(StringBuilder builder, String from, String to) {
    int index = builder.indexOf(from);
    while (index != -1) {
        builder.replace(index, index + from.length(), to);
        index += to.length(); // Move to the end of the replacement
        index = builder.indexOf(from, index);
    }//from w  w  w  . j a v  a2  s  . c o  m
}

From source file:org.apache.lucene.search.SearchUtil.java

public static String removeJspTags(String contents) {
    StringBuilder sb = new StringBuilder(contents);
    while (true) {
        if (sb.indexOf("<%") != -1 && sb.indexOf("%>") != -1) {
            int start = sb.indexOf("<%");
            int end = sb.indexOf("%>");
            sb.replace(start, end + 2, "");
        } else {//from   ww  w .  j a v  a  2 s .  c  o  m
            break;
        }
    }
    return sb.toString();
}

From source file:org.apache.lucene.search.SearchUtil.java

public static String removeDirty(String contents, String startStr, String endStr, int strLen) {
    StringBuilder sb = new StringBuilder(contents);
    while (true) {
        if (sb.indexOf(startStr) != -1 && sb.indexOf(endStr) != -1) {
            int start = sb.indexOf(startStr);
            int end = sb.indexOf(endStr);
            sb.replace(start, end + strLen, "");
        } else {/*  w  ww  .j av  a 2 s .  c  om*/
            break;
        }
    }
    return sb.toString();
}