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.jenkinsmvn.jenkins.api.http.AbstractHttpInvoker.java

protected HttpRequest createHttpRequest(String path) throws UnsupportedEncodingException {
    Validate.notNull(path, "path argument should not be null.");

    HttpRequest request;//from ww w. jav  a  2s.c  o m

    if (CollectionUtils.isNotEmpty(parameters) || (!getMethod && forceParametersOnPath)) {
        StringBuilder buf = new StringBuilder(path);

        if (buf.indexOf("?") != -1) {
            buf.append("&");
        } else {
            buf.append("?");
        }

        buf.append(URLEncodedUtils.format(parameters, UTF_8));
        path = buf.toString();
    }

    if (getMethod) {
        request = new HttpGet(path);
    } else {
        HttpPost post = new HttpPost(path);

        if (!forceParametersOnPath && CollectionUtils.isNotEmpty(parameters)) {
            post.setEntity(new UrlEncodedFormEntity(parameters, UTF_8));
        }

        request = post;
    }

    if (CollectionUtils.isNotEmpty(headers)) {
        for (Header header : headers) {
            request.addHeader(header);
        }
    }

    return request;
}

From source file:teletype.model.vk.Auth.java

private String getResponseUrl(StringBuilder contentText) {
    int begin = contentText.indexOf("action=") + 8;
    int end = contentText.indexOf("\"", begin);
    return contentText.substring(begin, end);
}

From source file:dhr.uploadtomicrobit.FirmwareGenerator.java

public 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   www  .j a  va 2  s. co m*/
}

From source file:de.acosix.alfresco.utility.share.surf.StateSafeExternalLessCssThemeHandler.java

/**
 *
 * {@inheritDoc}// w w w . j av a2s  . c  om
 */
@Override
public String processCssThemes(final String path, final StringBuilder cssContents) throws IOException {
    String result;
    // may be called on already processed CSS contents
    if (cssContents.indexOf(LESS_PROCESSED_MARKER) == -1) {
        final String superResult = super.processCssThemes(path, cssContents);
        result = LESS_PROCESSED_MARKER + "\n\n" + superResult;
    } else {
        result = cssContents.toString();
    }

    return result;
}

From source file:org.drools.guvnor.server.contenthandler.ModelContentHandler.java

private StringBuilder removeImportIfItExists(StringBuilder header, String importLine) {
    if (header.indexOf(importLine) >= 0) {
        int indexOfImportLine = header.indexOf(importLine);
        header = header.replace(indexOfImportLine, indexOfImportLine + importLine.length(), "");
    }//ww w  .j a  v  a 2 s  .c  o m
    return header;
}

From source file:eu.ggnet.dwoss.util.ImageFinder.java

public int nextImageId() {
    if (path == null || (!path.exists() && !path.isDirectory()))
        return -1;
    int max = 0;//from   w w  w. ja  v  a2s . co  m
    for (String name : path.list()) {
        StringBuilder rev = new StringBuilder(name);
        rev.reverse();
        int p = rev.indexOf(".");
        if (p < 0)
            continue;
        rev.delete(0, p + 1);
        p = rev.indexOf("_");
        if (p < 0)
            continue;
        rev.delete(p, rev.length());
        rev.reverse();
        int val = 0;
        try {
            val = Integer.parseInt(rev.toString());
        } catch (NumberFormatException e) {
            continue;
        }
        if (max < val)
            max = val;
    }
    return max + 1;
}

From source file:com.github.mojo.bdd.NoseMojo.java

@Override
protected void postExecute(StringBuilder output) throws MojoExecutionException, MojoFailureException {
    //workaround for a Nose/Freshen shortcoming where UNDEFINED steps do not fail the build
    if (output.indexOf("UNDEFINED") > 0) {
        getLog().error("UNDEFINED steps found! Failing build.");
        throw new MojoExecutionException("UNDEFINED steps found! Failing build.");
    }/*from  w ww  .ja v a 2 s .  c  o  m*/
}

From source file:teletype.model.vk.Auth.java

private String parseResponse(StringBuilder contentText, String value, int charCount) {
    int indexOf = contentText.indexOf(value);
    String returnValue = contentText.substring(indexOf + 13, indexOf + 13 + charCount);
    return returnValue;
}

From source file:org.pentaho.di.trans.steps.fileinput.text.TextFileInputUtils.java

public static final String[] convertLineToStrings(LogChannelInterface log, String line, TextFileInputMeta inf,
        String delimiter, String enclosure, String escapeCharacters) throws KettleException {
    String[] strings = new String[inf.inputFields.length];
    int fieldnr;/*from   w  w w.  j a  va2  s  .c o  m*/

    String pol; // piece of line

    try {
        if (line == null) {
            return null;
        }

        if (inf.content.fileType.equalsIgnoreCase("CSV")) {
            // Split string in pieces, only for CSV!

            fieldnr = 0;
            int pos = 0;
            int length = line.length();
            boolean dencl = false;

            int len_encl = (enclosure == null ? 0 : enclosure.length());
            int len_esc = (escapeCharacters == null ? 0 : escapeCharacters.length());

            while (pos < length) {
                int from = pos;
                int next;

                boolean encl_found;
                boolean contains_escaped_enclosures = false;
                boolean contains_escaped_separators = false;
                boolean contains_escaped_escape = false;

                // Is the field beginning with an enclosure?
                // "aa;aa";123;"aaa-aaa";000;...
                if (len_encl > 0 && line.substring(from, from + len_encl).equalsIgnoreCase(enclosure)) {
                    if (log.isRowLevel()) {
                        log.logRowlevel(BaseMessages.getString(PKG, "TextFileInput.Log.ConvertLineToRowTitle"),
                                BaseMessages.getString(PKG, "TextFileInput.Log.Encloruse",
                                        line.substring(from, from + len_encl)));
                    }
                    encl_found = true;
                    int p = from + len_encl;

                    boolean is_enclosure = len_encl > 0 && p + len_encl < length
                            && line.substring(p, p + len_encl).equalsIgnoreCase(enclosure);
                    boolean is_escape = len_esc > 0 && p + len_esc < length
                            && line.substring(p, p + len_esc).equalsIgnoreCase(inf.content.escapeCharacter);

                    boolean enclosure_after = false;

                    // Is it really an enclosure? See if it's not repeated twice or escaped!
                    if ((is_enclosure || is_escape) && p < length - 1) {
                        String strnext = line.substring(p + len_encl, p + 2 * len_encl);
                        if (strnext.equalsIgnoreCase(enclosure)) {
                            p++;
                            enclosure_after = true;
                            dencl = true;

                            // Remember to replace them later on!
                            if (is_escape) {
                                contains_escaped_enclosures = true;
                            }
                        } else if (strnext.equals(inf.content.escapeCharacter)) {
                            p++;
                            // Remember to replace them later on!
                            if (is_escape) {
                                contains_escaped_escape = true; // remember
                            }
                        }
                    }

                    // Look for a closing enclosure!
                    while ((!is_enclosure || enclosure_after) && p < line.length()) {
                        p++;
                        enclosure_after = false;
                        is_enclosure = len_encl > 0 && p + len_encl < length
                                && line.substring(p, p + len_encl).equals(enclosure);
                        is_escape = len_esc > 0 && p + len_esc < length
                                && line.substring(p, p + len_esc).equals(inf.content.escapeCharacter);

                        // Is it really an enclosure? See if it's not repeated twice or escaped!
                        if ((is_enclosure || is_escape) && p < length - 1) {

                            String strnext = line.substring(p + len_encl, p + 2 * len_encl);
                            if (strnext.equals(enclosure)) {
                                p++;
                                enclosure_after = true;
                                dencl = true;

                                // Remember to replace them later on!
                                if (is_escape) {
                                    contains_escaped_enclosures = true; // remember
                                }
                            } else if (strnext.equals(inf.content.escapeCharacter)) {
                                p++;
                                // Remember to replace them later on!
                                if (is_escape) {
                                    contains_escaped_escape = true; // remember
                                }
                            }
                        }
                    }

                    if (p >= length) {
                        next = p;
                    } else {
                        next = p + len_encl;
                    }

                    if (log.isRowLevel()) {
                        log.logRowlevel(BaseMessages.getString(PKG, "TextFileInput.Log.ConvertLineToRowTitle"),
                                BaseMessages.getString(PKG, "TextFileInput.Log.EndOfEnclosure", "" + p));
                    }
                } else {
                    encl_found = false;
                    boolean found = false;
                    int startpoint = from;
                    // int tries = 1;
                    do {
                        next = line.indexOf(delimiter, startpoint);

                        // See if this position is preceded by an escape character.
                        if (len_esc > 0 && next > 0) {
                            String before = line.substring(next - len_esc, next);

                            if (inf.content.escapeCharacter.equals(before)) {
                                int previous_escapes = 1;

                                int start = next - len_esc - 1;
                                int end = next - 1;

                                while (start >= 0) {
                                    if (inf.content.escapeCharacter.equals(line.substring(start, end))) {
                                        previous_escapes++;
                                        start--;
                                        end--;
                                    } else {
                                        break;
                                    }
                                }

                                // If behind the seperator there are a odd number of escaped
                                // The separator is escaped.
                                if (previous_escapes % 2 != 0) {
                                    // take the next separator, this one is escaped...
                                    startpoint = next + 1;
                                    // tries++;
                                    contains_escaped_separators = true;
                                } else {
                                    found = true;
                                }

                            } else {
                                found = true;
                            }
                        } else {
                            found = true;
                        }
                    } while (!found && next >= 0);
                }
                if (next == -1) {
                    next = length;
                }

                if (encl_found && ((from + len_encl) <= (next - len_encl))) {
                    pol = line.substring(from + len_encl, next - len_encl);
                    if (log.isRowLevel()) {
                        log.logRowlevel(BaseMessages.getString(PKG, "TextFileInput.Log.ConvertLineToRowTitle"),
                                BaseMessages.getString(PKG, "TextFileInput.Log.EnclosureFieldFound", "" + pol));
                    }
                } else {
                    pol = line.substring(from, next);
                    if (log.isRowLevel()) {
                        log.logRowlevel(BaseMessages.getString(PKG, "TextFileInput.Log.ConvertLineToRowTitle"),
                                BaseMessages.getString(PKG, "TextFileInput.Log.NormalFieldFound", "" + pol));
                    }
                }

                if (dencl && Utils.isEmpty(inf.content.escapeCharacter)) {
                    StringBuilder sbpol = new StringBuilder(pol);
                    int idx = sbpol.indexOf(enclosure + enclosure);
                    while (idx >= 0) {
                        sbpol.delete(idx, idx + enclosure.length());
                        idx = sbpol.indexOf(enclosure + enclosure);
                    }
                    pol = sbpol.toString();
                }

                // replace the escaped enclosures with enclosures...
                if (contains_escaped_enclosures) {
                    String replace = inf.content.escapeCharacter + enclosure;
                    String replaceWith = enclosure;

                    pol = Const.replace(pol, replace, replaceWith);
                }

                // replace the escaped separators with separators...
                if (contains_escaped_separators) {
                    String replace = inf.content.escapeCharacter + delimiter;
                    String replaceWith = delimiter;

                    pol = Const.replace(pol, replace, replaceWith);
                }

                // replace the escaped escape with escape...
                contains_escaped_escape = pol
                        .contains(inf.content.escapeCharacter + inf.content.escapeCharacter);
                if (contains_escaped_escape) {
                    String replace = inf.content.escapeCharacter + inf.content.escapeCharacter;
                    String replaceWith = inf.content.escapeCharacter;

                    pol = Const.replace(pol, replace, replaceWith);
                }

                // Now add pol to the strings found!
                try {
                    strings[fieldnr] = pol;
                } catch (ArrayIndexOutOfBoundsException e) {
                    // In case we didn't allocate enough space.
                    // This happens when you have less header values specified than there are actual values in the rows.
                    // As this is "the exception" we catch and resize here.
                    //
                    String[] newStrings = new String[strings.length];
                    for (int x = 0; x < strings.length; x++) {
                        newStrings[x] = strings[x];
                    }
                    strings = newStrings;
                }

                pos = next + delimiter.length();
                fieldnr++;
            }
            if (pos == length) {
                if (log.isRowLevel()) {
                    log.logRowlevel(BaseMessages.getString(PKG, "TextFileInput.Log.ConvertLineToRowTitle"),
                            BaseMessages.getString(PKG, "TextFileInput.Log.EndOfEmptyLineFound"));
                }
                if (fieldnr < strings.length) {
                    strings[fieldnr] = Const.EMPTY_STRING;
                }
                fieldnr++;
            }
        } else {
            // Fixed file format: Simply get the strings at the required positions...
            // Note - charBased is the old default behavior. If this is an old transformation, content.length will be null
            // and should be processed as before. If the content.length is equal to "Characters" or there is no specified encoding,
            // it will still use the old behavior. The *only* way to get the new behavior is if content.length = "Bytes" and
            // the encoding is specified.
            boolean charBased = (inf.content.length == null || inf.content.length.equalsIgnoreCase("Characters")
                    || inf.getEncoding() == null); // Default to classic behavior
            for (int i = 0; i < inf.inputFields.length; i++) {
                BaseFileField field = inf.inputFields[i];

                int length;
                int fPos = field.getPosition();
                int fLength = field.getLength();
                int fPl = fPos + fLength;
                if (charBased) {
                    length = line.length();
                    if (fPl <= length) {
                        strings[i] = line.substring(fPos, fPl);
                    } else {
                        if (fPos < length) {
                            strings[i] = line.substring(fPos);
                        } else {
                            strings[i] = "";
                        }
                    }
                } else {
                    byte[] b = null;
                    String enc = inf.getEncoding();
                    b = line.getBytes(enc);
                    length = b.length;
                    if (fPl <= length) {
                        strings[i] = new String(Arrays.copyOfRange(b, fPos, fPl), enc);
                    } else {
                        if (fPos < length) {
                            strings[i] = new String(Arrays.copyOfRange(b, fPos, length - 1), enc);
                        } else {
                            strings[i] = "";
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new KettleException(
                BaseMessages.getString(PKG, "TextFileInput.Log.Error.ErrorConvertingLine", e.toString()), e);
    }

    return strings;
}

From source file:org.sonatype.nexus.plugins.rrb.MavenRepositoryReader.java

/**
 * Used to detect error in S3 response.//w w w.j a v  a  2  s  .  c om
 */
private boolean responseContainsError(StringBuilder indata) {
    return indata.indexOf("<Error>") != -1 || indata.indexOf("<error>") != -1;
}