Example usage for java.lang StringBuilder charAt

List of usage examples for java.lang StringBuilder charAt

Introduction

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

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:org.apache.lucene.gdata.server.GDataRequest.java

private String buildRequestIDString(boolean endingSlash) {
    StringBuilder builder = new StringBuilder("http://");
    builder.append(this.request.getHeader("Host"));
    builder.append(this.request.getRequestURI());
    if (!endingSlash && builder.charAt(builder.length() - 1) == '/')
        builder.setLength(builder.length() - 1);
    if (endingSlash && builder.charAt(builder.length() - 1) != '/')
        builder.append("/");

    return builder.toString();
}

From source file:org.eclipse.smila.ode.ODEServer.java

/**
 * create tables and aliases in in-memory HSQLDB.
 * // w  ww .ja  va 2 s.  com
 * @throws ODEServerException
 *           error creating tables
 */
private void prepareSchedulerDb() throws ODEServerException {
    Connection c = null;
    String sqlScriptName = null;
    if ("org.apache.derby.jdbc.EmbeddedDriver".equals(_odeConfig.getDbInternalJdbcDriverClass())) {
        sqlScriptName = RESOURCE_SCHEDULER_DERBY_SQL;
    } else if ("org.hsqldb.jdbcDriver".equals(_odeConfig.getDbInternalJdbcDriverClass())) {
        sqlScriptName = RESOURCE_SCHEDULER_HSQLDB_SQL;
    }
    // init some tables in DB
    if (sqlScriptName != null) {
        try {
            c = _dataSource.getConnection();
            _log.info("Reading SQL commands from " + sqlScriptName + " to prepare DB for scheduler.");
            final InputStream sqlStream = getClass().getResourceAsStream(sqlScriptName);
            if (sqlStream == null) {
                _log.error("Error reading SQL script " + sqlScriptName);
                throw new ODEServerException("Error reading SQL script " + sqlScriptName);
            }
            final BufferedReader reader = new BufferedReader(new InputStreamReader(sqlStream));
            String line = null;
            StringBuilder sql = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                sql.append(line.trim());
                if (sql.length() > 0 && sql.charAt(sql.length() - 1) == ';') {
                    // cut off ";", Derby doesn't like it.
                    sql.setLength(sql.length() - 1);
                    c.createStatement().execute(sql.toString());
                    sql = new StringBuilder();
                }
            }
            reader.close();
        } catch (final IOException ex) {
            throw new ODEServerException("Error reading SQL script: " + ex.getMessage(), ex);
        } catch (final SQLException ex) {
            _log.info("Error creating tables in scheduler DB: " + ex.toString());
            _log.info("Usually this means that the DB has been initialized earlier already, "
                    + "in this case everything should be fine.");
        } finally {
            try {
                if (c != null) {
                    c.close();
                }
            } catch (SQLException ex) {
                ex = null; // ignorable.
            }
        }
    }
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.CgroupsLCEResourcesHandler.java

public String getResourcesOption(ContainerId containerId) {
    String containerName = containerId.toString();

    StringBuilder sb = new StringBuilder("cgroups=");

    if (isCpuWeightEnabled()) {
        sb.append(pathForCgroup(CONTROLLER_CPU, containerName) + "/tasks");
        sb.append(PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR);
    }/*from  ww  w .j a va2s  .  c  om*/

    if (sb.charAt(sb.length() - 1) == PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR) {
        sb.deleteCharAt(sb.length() - 1);
    }

    return sb.toString();
}

From source file:com.dal.unity.Config.java

private String readClasspath(String classpathFile) {
    StringBuilder result = new StringBuilder(128);
    try (InputStream is = Config.class.getClassLoader().getResourceAsStream(classpathFile);
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);) {
        String line;//from  w w w.  j  av  a  2 s. c  o  m
        while (null != (line = br.readLine())) {
            if (result.length() > 0 && File.pathSeparatorChar != result.charAt(result.length() - 1)) {
                result.append(File.pathSeparatorChar);
            }
            result.append(line);
        }
    } catch (IOException x) {
        LOG.error("Failure attempting to read classpath file {}", classpathFile, x);
    }

    return result.toString();
}

From source file:com.nappingcoder.jutil.http.HttpUrlBuilder.java

/**
 * //  ww  w .j av a  2 s . com
 * Build a new HTTP URL string.
 *  
 * @return
 * @throws IllegalStateException
 */
public String toString() {

    verifyState();

    StringBuilder url = new StringBuilder();

    url.append(_protocol).append("://").append(_host);

    if (_port > 0) {
        url.append(":" + _port);
    }

    if (_path.length() > 0) {

        if (_path.length() > 0 && _path.charAt(_path.length() - 1) == '/') {
            _path.setLength(_path.length() - 1);
        }

        url.append("/").append(_path);
    }

    if (_query.length() > 0) {
        url.append("?").append(_query);
    }

    if (url.charAt(url.length() - 1) == '&') {
        url.setLength(url.length() - 1);
    }

    return url.toString();
}

From source file:hudson.tasks.junit.CaseResult.java

/**
 * Gets the version of {@link #getName()} that's URL-safe.
 *//*from  w w w  .ja v  a 2s  . c o m*/
public @Override synchronized String getSafeName() {
    if (safeName != null) {
        return safeName;
    }
    StringBuilder buf = new StringBuilder(testName);
    for (int i = 0; i < buf.length(); i++) {
        char ch = buf.charAt(i);
        if (!Character.isJavaIdentifierPart(ch))
            buf.setCharAt(i, '_');
    }
    Collection<CaseResult> siblings = (classResult == null ? Collections.<CaseResult>emptyList()
            : classResult.getChildren());
    return safeName = uniquifyName(siblings, buf.toString());
}

From source file:com.g3net.tool.StringUtils.java

/**
 * Trim leading whitespace from the given String.
 * /*  w  w w.  j a v  a 2s.c o  m*/
 * @param str
 *            the String to check
 * @return the trimmed String
 * @see java.lang.Character#isWhitespace
 */
public static String trimLeadingWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder buf = new StringBuilder(str);
    while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
        buf.deleteCharAt(0);
    }
    return buf.toString();
}

From source file:au.org.ala.delta.directives.DirectiveParser.java

private boolean isDelimited(AbstractDirective<C> directive, StringBuilder data) {

    if (!directive.canSpecifyTextDelimiter()) {
        return false;
    }//from  www. ja v  a 2s. c o m

    // Read the first 'word'
    String word = readWord(data, 0, true);
    if (word.length() == 1 && ILLEGAL_TEXT_DELIMITERS.indexOf(word.charAt(0)) < 0) {
        char delim = word.charAt(0);
        boolean inDelim = false;
        for (int i = data.indexOf(word) + 1; i < data.length(); ++i) {
            if (data.charAt(i) == delim) {
                inDelim = !inDelim;
            }
        }
        return inDelim;
    }

    return false;
}

From source file:com.google.jenkins.flakyTestHandler.junit.FlakyCaseResult.java

/**
 * Gets the version of {@link #getName()} that's URL-safe.
 *///from   www . jav a2s.c o  m
public @Override synchronized String getSafeName() {
    if (safeName != null) {
        return safeName;
    }
    StringBuilder buf = new StringBuilder(testName);
    for (int i = 0; i < buf.length(); i++) {
        char ch = buf.charAt(i);
        if (!Character.isJavaIdentifierPart(ch))
            buf.setCharAt(i, '_');
    }
    Collection<FlakyCaseResult> siblings = (classResult == null ? Collections.<FlakyCaseResult>emptyList()
            : classResult.getChildren());
    return safeName = uniquifyName(siblings, buf.toString());
}

From source file:com.g3net.tool.StringUtils.java

/**
 * Trim leading and trailing whitespace from the given String.
 * //  w  w w .j  a  v a  2  s. c  om
 * @param str
 *            the String to check
 * @return the trimmed String
 * @see java.lang.Character#isWhitespace
 */
public static String trimWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder buf = new StringBuilder(str);
    while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
        buf.deleteCharAt(0);
    }
    while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) {
        buf.deleteCharAt(buf.length() - 1);
    }
    return buf.toString();
}