Example usage for java.lang StringBuilder lastIndexOf

List of usage examples for java.lang StringBuilder lastIndexOf

Introduction

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

Prototype

@Override
    public int lastIndexOf(String str) 

Source Link

Usage

From source file:org.jclouds.azure.storage.filters.SharedKeyAuthentication.java

private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) {
    Set<String> headers = new TreeSet<String>(request.getHeaders().keySet());
    for (String header : headers) {
        if (header.startsWith("x-ms-")) {
            toSign.append(header.toLowerCase()).append(":");
            for (String value : request.getHeaders().get(header))
                toSign.append(value.replaceAll("\r?\n", "")).append(",");
            toSign.deleteCharAt(toSign.lastIndexOf(","));
            toSign.append("\n");
        }//from   w w w .  j  a  v  a 2 s .  c  o  m
    }
}

From source file:org.jclouds.aws.s3.filters.RequestAuthorizeSignature.java

private void appendAmzHeaders(HttpRequest request, StringBuilder toSign) {
    Set<String> headers = new TreeSet<String>(request.getHeaders().keySet());
    for (String header : headers) {
        if (header.startsWith("x-amz-")) {
            toSign.append(header.toLowerCase()).append(":");
            for (String value : request.getHeaders().get(header))
                toSign.append(value.replaceAll("\r?\n", "")).append(",");
            toSign.deleteCharAt(toSign.lastIndexOf(","));
            toSign.append("\n");
        }//ww  w . j  a  v  a 2s.  co m
    }
}

From source file:org.jumpmind.db.sql.SqlScriptReader.java

public String readSqlStatement() {
    try {// www .j  ava  2  s .c o m
        String line = readLine();
        StringBuilder sql = null;
        if (line != null) {
            do {
                line = trimComments(line);
                if (sql == null) {
                    sql = new StringBuilder();
                }
                sql.append("\n");
                sql.append(line);

                if (checkStatementEnds(sql.toString())) {
                    String toExecute = sql.substring(0, sql.lastIndexOf(delimiter));
                    toExecute = prepareForExecute(toExecute);
                    if (StringUtils.isNotBlank(toExecute)) {
                        return toExecute;
                    } else {
                        sql.setLength(0);
                    }
                }
                line = readLine();
            } while (line != null);

            String toExecute = sql.toString();
            if (StringUtils.isNotBlank(toExecute)) {
                return prepareForExecute(toExecute);
            } else {
                return null;
            }
        } else {
            return null;
        }

    } catch (IOException ex) {
        throw new IoException(ex);
    }

}

From source file:org.wso2.carbon.identity.mgt.store.InMemoryIdentityDataStore.java

@Override
public UserIdentityClaimsDO load(String userName, UserStoreManager userStoreManager) {

    Cache<String, UserIdentityClaimsDO> cache = getCache();
    if (userName != null && cache != null) {
        if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) {
            if (!IdentityUtil
                    .isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager) userStoreManager)) {
                if (log.isDebugEnabled()) {
                    log.debug("Case insensitive user store found. Changing username from : " + userName
                            + " to : " + userName.toLowerCase());
                }// www . j  a v a  2s .c om
                userName = userName.toLowerCase();
            }
        }

        org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager) userStoreManager;

        String domainName = store.getRealmConfiguration()
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);

        UserIdentityClaimsDO userIdentityDTO = (UserIdentityClaimsDO) cache
                .get(domainName + CarbonContext.getThreadLocalCarbonContext().getTenantId() + userName);

        if (userIdentityDTO != null && log.isDebugEnabled()) {
            StringBuilder data = new StringBuilder("{");
            if (userIdentityDTO.getUserIdentityDataMap() != null) {
                for (Map.Entry<String, String> entry : userIdentityDTO.getUserIdentityDataMap().entrySet()) {
                    data.append("[" + entry.getKey() + " = " + entry.getValue() + "], ");
                }
            }
            if (data.indexOf(",") >= 0) {
                data.deleteCharAt(data.lastIndexOf(","));
            }
            data.append("}");
            log.debug("Loaded UserIdentityClaimsDO from cache for user :" + userName + " with claims: " + data);

        }
        return userIdentityDTO;
    }
    return null;
}

From source file:sapience.injectors.stax.inject.StringBasedStaxStreamInjector.java

/**
 * Helper method, taking a XML string like <ows:Metadata xmlns:ows=\"http://ogc.org/ows\" xmlns:xlink=\"http://wrc.org/xlink\" 
 * xlink:href=\"http://dude.com\"></ows:Metadata> from the reference 
 * and checks if //w  ww.ja  v a2s.  c om
 * a  the used prefixes match the globally used ones and
 * b) any of the declared namespaces are redundant 
 * 
 * The same is true for the XPath definition
 * 
 * @param resultingXMLString
 * @param context
 */
private void processNamespace(StringBuilder sb, NamespaceContext global, LocalNamespaceContext local) {

    Matcher prefixMatcher = prefixPattern.matcher(sb);
    Matcher nsMatcher = nsPattern.matcher(sb);
    String prefix;
    String uri;

    /* process the local namespaces */
    while (nsMatcher.find()) {
        int start = nsMatcher.start();
        int end = nsMatcher.end();
        StringBuilder sbu = new StringBuilder(sb.substring(start, end));
        String thisPrefix = sbu.substring(sbu.indexOf(":") + 1, sbu.lastIndexOf("="));
        String thisUri = sbu.substring(sbu.indexOf("\"") + 1, sbu.lastIndexOf("\""));
        // add to local namespace context
        local.put(thisPrefix, thisUri);

        if ((prefix = global.getPrefix(thisUri)) != null) {
            // namespace is registered, let's remove it
            sb.delete(start - 1, end);

            // we have to reset, since we changed the state of the matched string with the deletion
            nsMatcher.reset();
        }

    }

    /* change the prefixes */
    try {
        while (prefixMatcher.find()) {
            int start = prefixMatcher.start();
            int end = prefixMatcher.end();

            String localprefix = sb.substring(start + 1, end - 1);
            if ((global.getNamespaceURI(localprefix) == null)
                    && (uri = local.getNamespaceURI(localprefix)) != null) {
                // get the other prefix
                prefix = global.getPrefix(uri);

                if ((prefix != null) && (!(localprefix.contentEquals(prefix)))) {
                    sb.replace(start + 1, end - 1, prefix);
                    prefixMatcher.reset();
                }
            }
        }
    } catch (StringIndexOutOfBoundsException e) {
        // we do nothing here
    }

}

From source file:com.nway.spring.jdbc.SqlExecutor.java

/**
 *
 * @param sql/*from w  ww. java2  s  .co  m*/
 *            SQL
 * @return
 */
private String buildPaginationCountSql(String sql) {

    StringBuilder countSql = new StringBuilder(sql);

    if (SQL_ORDER_BY_PATTERN.matcher(countSql).matches()) {

        countSql.delete(countSql.lastIndexOf(" ORDER "), countSql.length());
    }

    int firstFromIndex = firstFromIndex(sql, 0);

    String selectedColumns = countSql.substring(0, firstFromIndex + 1);

    if (selectedColumns.indexOf(" DISTINCT ") == -1 && !SQL_TOP_PATTERN.matcher(selectedColumns).matches()) {

        countSql = countSql.delete(0, firstFromIndex).insert(0, "SELECT COUNT(1)");
    } else {

        countSql.insert(0, "SELECT COUNT(1) FROM (").append(')');
    }

    return countSql.toString();
}

From source file:com.taobao.datax.plugins.writer.mysqlwriter.MysqlWriter.java

private String splitColumns(String colorder) {
    String[] columns = colorder.split(",");
    StringBuilder sb = new StringBuilder();
    for (String column : columns) {
        sb.append(quoteData(column.trim()) + ",");
    }/*from   w w w .ja  va  2s  . c o  m*/
    return sb.substring(0, sb.lastIndexOf(","));
}

From source file:pt.webdetails.cfr.file.MetadataReader.java

private String toStringArray(FilePermissionEnum[] allowedPermissions) {
    StringBuilder result = new StringBuilder("[");
    Set<FilePermissionEnum> permissions = new LinkedHashSet<FilePermissionEnum>(
            Arrays.asList(allowedPermissions));

    for (FilePermissionEnum elem : permissions) {
        result.append("'").append(elem.getId()).append("',");
    }//from   ww w  . ja  v  a 2  s  .c  om

    int index = result.lastIndexOf(",");
    if (index > 0) {
        result.deleteCharAt(index);
    }

    result.append("]");

    return result.toString();
}

From source file:org.codelabor.system.xplatform.ant.Xml2bin.java

/**
 * Generates .ini file.//from  w ww .ja v  a2  s  . c  o  m
 */
protected void generateIni() {
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(iniFile), encoding);
        validateAttributes();
        DirectoryScanner ds = null;

        StringBuilder row = new StringBuilder();
        for (FileSet fileSet : fileSets) {
            ds = fileSet.getDirectoryScanner(getProject());
            File baseDir = ds.getBasedir();
            if (destDir == null) {
                destDir = baseDir;
            }
            log("baseDir: " + baseDir.toString(), verbosity);
            log("destDir: " + destDir.toString(), verbosity);
            String[] includedFileNames = ds.getIncludedFiles();

            log(TAB + "file count:" + includedFileNames.length, verbosity);

            for (String includedFileName : includedFileNames) {
                log(TAB + "included file name: " + includedFileName, verbosity);

                // source path
                StringBuilder sourcePath = new StringBuilder();
                sourcePath.append(baseDir);
                sourcePath.append(FILE_SEPARATOR);
                sourcePath.append(includedFileName);
                validatePathLength(sourcePath.toString());

                // target path
                StringBuilder targetPath = new StringBuilder();
                targetPath.append(destDir);
                targetPath.append(FILE_SEPARATOR);
                targetPath.append(includedFileName);
                validatePathLength(targetPath.toString());

                // first column
                row.append("1");
                row.append(",");

                // second column
                row.append(sourcePath.toString());
                row.append(",");

                // third column
                row.append(targetPath.toString());
                row.append(LINE_SEPARATOR);

                // make destination directory
                StringBuilder destDirFullyQualifiedPath = new StringBuilder();
                destDirFullyQualifiedPath.append(targetPath.toString());
                int lastIndex = destDirFullyQualifiedPath.lastIndexOf(FILE_SEPARATOR);
                destDirFullyQualifiedPath.delete(lastIndex, destDirFullyQualifiedPath.length());
                File destDirFinal = new File(destDirFullyQualifiedPath.toString());
                FileUtils.forceMkdir(destDirFinal);

                log(TAB + "make dir: " + destDirFullyQualifiedPath.toString(), verbosity);

            }
            writer.write(row.toString());
            writer.flush();
        }
    } catch (IOException e) {
        if (failonerror) {
            throw new BuildException(e);
        } else {
            log("Warning: " + getMessage(e), Project.MSG_ERR);
        }
    } finally {
        try {
            if (writer != null) {
                writer.close();
            }
        } catch (IOException e) {
            if (failonerror) {
                throw new BuildException(e);
            } else {
                log("Warning: " + getMessage(e), Project.MSG_ERR);
            }
        }
    }
}

From source file:savant.plugin.Tool.java

/**
 * Get the local file which contains the data for the given argument.
 *
 * @param t URI of the track which is providing the data, or a local file
 * @param loc string specifying ref and range to be processed
 * @param canUseDirectly for bam files, Savant uses them natively, so we may be able to use a local file directly
 *///from  www .  j a v  a 2s. c  o m
private File getLocalFile(String fileOrURI, boolean canUseDirectly) throws IOException {

    URI uri = NetworkUtils.getURIFromPath(fileOrURI);

    // If the data source is a local bam file, we can just use it.
    if (canUseDirectly) {
        if (uri.getScheme().equals("file")) {
            return new File(uri);
        }
    }

    // Track is remote.  We'll need to download it.
    StringBuilder source = new StringBuilder(uri.toString());
    int savantExt = source.lastIndexOf(".savant");
    if (savantExt > 0) {
        source.setLength(savantExt);
    }

    // File may represent only a partial track.  We may need to fetch it afresh,
    // or it may already be in our cache.
    if (RemoteFileCache.findCacheEntry(source.toString()) == null) {
        // Couldn't find exported file for full genome.  Perhaps just for the current chromosome?
        if (workingRef != null) {
            int lastDot = source.lastIndexOf(".");
            source.insert(lastDot, "-" + workingRef);
            if (RemoteFileCache.findCacheEntry(source.toString()) == null) {
                if (workingRange != null) {
                    // No existing chromosome file, so just request the subrange of interest.
                    lastDot = source.lastIndexOf(".");
                    source.insert(lastDot,
                            String.format(":%d-%d", workingRange.getFrom(), workingRange.getTo()));
                }
            }
        }
    }

    return RemoteFileCache.getCacheFile(uri.toURL(), source.toString(), 0, 0);
}