Example usage for org.apache.commons.lang StringUtils chop

List of usage examples for org.apache.commons.lang StringUtils chop

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils chop.

Prototype

public static String chop(String str) 

Source Link

Document

Remove the last character from a String.

Usage

From source file:org.apache.hcatalog.cli.HCatCli.java

private static int processLine(String line) {
    int ret = 0;/*from   w  w w . ja v a2  s.c o m*/

    String command = "";
    for (String oneCmd : line.split(";")) {

        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + ";";
            continue;
        } else {
            command += oneCmd;
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCmd(command);
        command = "";
    }
    return ret;
}

From source file:org.apache.hive.jdbc.beeline.HiveBeeline.java

public static void main(String[] args) throws Exception {
    OptionsProcessor oproc = new OptionsProcessor();
    if (!oproc.processArgs(args)) {
        System.exit(1);/*  w w w.j ava  2s  . c o m*/
    }

    // assemble connection URL
    String jdbcURL = URI_PREFIX;
    if (oproc.getHost() != null) {
        // no, host name indicates an embbeded hive invocation
        jdbcURL += oproc.getHost() + ":" + oproc.getPort();
    }

    if (!oproc.getDatabase().isEmpty()) {
        jdbcURL += URL_DB_MARKER + oproc.getDatabase();
    }
    if (!oproc.getSessVars().isEmpty()) {
        jdbcURL += URL_SESS_VAR_MARKER + oproc.getSessVars();
    }
    if (!oproc.getHiveConfs().isEmpty()) {
        jdbcURL += URL_HIVE_CONF_MARKER + oproc.getHiveConfs();
    }
    if (!oproc.getHiveVars().isEmpty()) {
        jdbcURL += URL_HIVE_VAR_MARKER + oproc.getHiveVars();
    }

    // setup input file or string
    InputStream sqlLineInput = null;
    if (oproc.getFileName() != null) {
        String scriptCmd = SQLLINE_SCRIPT_CMD + " " + oproc.getFileName().trim() + "\n";
        sqlLineInput = new ByteArrayInputStream(scriptCmd.getBytes());
    } else if (oproc.getExecString() != null) {
        // process the string to make each stmt a separate line
        String execString = oproc.getExecString().trim();
        String execCommand = "";
        String command = "";
        for (String oneCmd : execString.split(";")) {
            if (StringUtils.endsWith(oneCmd, "\\")) {
                command += StringUtils.chop(oneCmd) + ";";
                continue;
            } else {
                command += oneCmd;
            }
            if (StringUtils.isBlank(command)) {
                continue;
            }
            execCommand += command + ";\n"; // stmt should end with ';' for sqlLine
            command = "";
        }
        sqlLineInput = new ByteArrayInputStream(execCommand.getBytes());
    }

    // setup SQLLine args
    List<String> argList = new ArrayList<String>();
    argList.add("-u");
    argList.add(jdbcURL);
    argList.add("-d");
    argList.add(HIVE_JDBC_DRIVER); // TODO: make it configurable for HS or HS2
    if (oproc.getpMode() == PrintMode.SILENT) {
        argList.add(SQLLINE_SILENT);
    } else if (oproc.getpMode() == PrintMode.VERBOSE) {
        argList.add(SQLLINE_VERBOSE);
    }

    // Invoke sqlline
    SqlLine.mainWithInputRedirection(argList.toArray(new String[0]), sqlLineInput);
}

From source file:org.codice.proxy.http.HttpProxyWrappedCleanRequest.java

@Override
public String getQueryString() {
    String queryString = super.getQueryString();
    // If query string ends with an ampersand, take it off
    if (StringUtils.endsWith(queryString, "&")) {
        queryString = StringUtils.chop(queryString);
    }/*from  w  w  w  .j a va 2  s . c om*/
    return queryString;
}

From source file:org.eclipse.skalli.core.rest.admin.StatisticsQuery.java

private long getTimeInterval(String param) {
    long timeInterval = 0;
    if (StringUtils.isNotBlank(param)) {
        int defaultValue = 0;
        TimeUnit unit = TimeUnit.DAYS;
        char unitSymbol = param.charAt(param.length() - 1);
        if (unitSymbols.indexOf(unitSymbol) >= 0) {
            if (unitSymbol == 'h' || unitSymbol == 'H') {
                unit = TimeUnit.HOURS;
            } else if (unitSymbol == 'm' || unitSymbol == 'M') {
                unit = TimeUnit.MINUTES;
            }/*from  w w  w.  j  a  va  2 s  . c  o  m*/
            param = StringUtils.chop(param);
            defaultValue = 1;
        }
        int value = NumberUtils.toInt(param, defaultValue);
        if (value != 0) {
            timeInterval = TimeUnit.MILLISECONDS.convert(value, unit);
        }
    }
    return timeInterval;
}

From source file:org.huahinframework.manager.rest.service.HiveService.java

@Path("/execute")
@POST/* www.  j  a v a  2  s  .  c o m*/
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaTypeUtils.MULTIPART_FORM_DATA)
public void execute(@Context HttpServletResponse response, InMultiPart inMP) throws IOException {
    OutputStreamWriter out = null;
    Map<String, String> status = new HashMap<String, String>();
    Map<String, Object> result = new HashMap<String, Object>();
    try {
        out = new OutputStreamWriter(response.getOutputStream());
        if (!inMP.hasNext()) {
            status.put(Response.STATUS, "Query is empty");
            out.write(new JSONObject(status).toString());
            out.flush();
            out.close();
            return;
        }

        JSONObject argument = createJSON(inMP.next().getInputStream());
        String query = argument.getString(JSON_QUERY);
        if (query == null || query.isEmpty()) {
            status.put(Response.STATUS, "Query is empty");
            out.write(new JSONObject(status).toString());
            out.flush();
            out.close();
            return;
        }

        Class.forName(driverName);
        Connection con = DriverManager.getConnection(String.format(connectionFormat, hiveserver), "", "");
        Statement stmt = con.createStatement();

        int queryNo = 1;
        String command = "";
        for (String oneCmd : query.split(";")) {
            if (StringUtils.endsWith(oneCmd, "")) {
                command += StringUtils.chop(oneCmd) + ";";
                continue;
            } else {
                command += oneCmd;
            }

            if (StringUtils.isBlank(command)) {
                continue;
            }

            boolean b = stmt.execute(command);
            if (b) {
                result.clear();
                result.put(JSON_QUERY, queryNo);

                ResultSet resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    JSONObject jsonObject = new JSONObject();
                    for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
                        jsonObject.put(resultSet.getMetaData().getColumnName(i), resultSet.getString(i));
                    }
                    result.put(RESULT, jsonObject);

                    out.write(new JSONObject(result).toString());
                    out.flush();
                }

                if (result.size() == 1) {
                    status.put(Response.STATUS, "SCCESS");
                    result.put(RESULT, status);

                    JSONObject jsonObject = new JSONObject(result);
                    out.write(jsonObject.toString());
                    out.flush();
                }
            } else {
                result.clear();
                status.clear();

                result.put(JSON_QUERY, queryNo);

                status.put(Response.STATUS, "SCCESS");
                result.put(RESULT, status);

                JSONObject jsonObject = new JSONObject(result);
                out.write(jsonObject.toString());
                out.flush();
            }

            command = "";
            queryNo++;
        }

        con.close();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e);
        if (out != null) {
            status.put(Response.STATUS, e.getMessage());
            out.write(new JSONObject(status).toString());
            out.flush();
            out.close();
        }
    }
}

From source file:org.hydracache.server.httpd.handler.BaseHttpMethodHandler.java

protected String extractRequestString(final String requestUri) {
    String cleanUri = StringUtils.trim(requestUri);

    if (cleanUri.endsWith(SLASH)) {
        cleanUri = StringUtils.chop(cleanUri);
    }/*from w w  w  .  ja  v a 2  s  . c o m*/

    cleanUri = StringUtils.removeStart(cleanUri, SLASH);

    String requestString = cleanUri;

    if (StringUtils.contains(requestString, SLASH)) {
        requestString = StringUtils.substringAfter(requestString, SLASH);
    }

    if (StringUtils.contains(requestString, QUESTION_MARK)) {
        requestString = StringUtils.substringBefore(requestString, QUESTION_MARK);
    }

    return requestString;
}

From source file:org.kaaproject.kaa.server.common.thrift.cli.client.BaseCliThriftClient.java

/**
 * Process command line./*from w  ww . j  av  a2  s  .co m*/
 *
 * @param line the command line
 * @return the int execution result code
 */
public int processLine(String line) {
    int lastRet = 0;
    int ret = 0;

    String command = "";
    for (String oneCmd : line.split(";")) {
        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + ";";
            continue;
        } else {
            command += oneCmd;
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCmd(command);
        command = "";
        lastRet = ret;
        if (ret != 0) {
            return ret;
        }

    }
    return lastRet;
}

From source file:org.kaaproject.kaa.server.control.cli.ControlApiCliThriftClient.java

/**
 * Process command line./* w  ww . j av  a 2s.  c o m*/
 *
 * @param line
 *            the command line
 * @return the int execution result code
 */
public int processLine(String line) {
    int lastRet = 0, ret = 0;

    String command = "";
    for (String oneCmd : line.split(";")) {
        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + ";";
            continue;
        } else {
            command += oneCmd;
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCmd(command);
        command = "";
        lastRet = ret;
        if (ret != 0) {
            return ret;
        }

    }
    return lastRet;
}

From source file:org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase.java

/**
 * Replaces references to collection elements to their respective plural names WARNING: this method is totally lame and I for
 * one wished it didn't have to exist// w w  w  .  j a v  a  2  s.c o  m
 *
 * @param name the property name with perhaps collection elements in
 * @return the corrected name
 */
protected String replaceCollectionElementsWithPlurals(String name) {
    //KFSMI-9923 - modified to replace collection elements in each part of the name otherwise prefixes could end up
    //with the unwanted double "s" (ex: targetAccountingLiness.financialObjectCode)
    String newName = "";
    String[] names = name.split("\\.");
    for (int i = 0; i < names.length; i++) {
        String temp = names[i].replaceAll("\\[\\d+\\]", "s");
        // now - need to check if the property name ends with a double "s", which is incorrect
        if (temp.endsWith("ss")) {
            temp = StringUtils.chop(temp);
        }
        if (i > 0) {
            newName += "." + temp;
        } else {
            newName = temp;
        }
    }
    return newName;
}

From source file:org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase.java

/**
 * Replaces references to collection elements to their respective plural names WARNING: this method is totally lame and I for
 * one wished it didn't have to exist//  ww  w.  j  a  v  a  2 s .co m
 * 
 * @param name the property name with perhaps collection elements in
 * @return the corrected name
 */
protected String replaceCollectionElementsWithPlurals(String name) {
    String temp = name.replaceAll("\\[\\d+\\]", "s");
    // now - need to check if the property name ends with a double "s", which is incorrect
    if (temp.endsWith("ss")) {
        temp = StringUtils.chop(temp);
    }
    return temp;
}