Search in sources :

Example 1 with String

use of java.lang.String in project clojure by clojure.

the class LispReader method matchSymbol.

private static Object matchSymbol(String s) {
    Matcher m = symbolPat.matcher(s);
    if (m.matches()) {
        int gc = m.groupCount();
        String ns = m.group(1);
        String name = m.group(2);
        if (ns != null && ns.endsWith(":/") || name.endsWith(":") || s.indexOf("::", 1) != -1)
            return null;
        if (s.startsWith("::")) {
            Symbol ks = Symbol.intern(s.substring(2));
            Namespace kns;
            if (ks.ns != null)
                kns = Compiler.namespaceFor(ks);
            else
                kns = Compiler.currentNS();
            //auto-resolving keyword
            if (kns != null)
                return Keyword.intern(kns.name.name, ks.name);
            else
                return null;
        }
        boolean isKeyword = s.charAt(0) == ':';
        Symbol sym = Symbol.intern(s.substring(isKeyword ? 1 : 0));
        if (isKeyword)
            return Keyword.intern(sym);
        return sym;
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) String(java.lang.String)

Example 2 with String

use of java.lang.String in project DeepLinkDispatch by airbnb.

the class DeepLinkDelegate method dispatchFrom.

public DeepLinkResult dispatchFrom(Activity activity, Intent sourceIntent) {
    if (activity == null) {
        throw new NullPointerException("activity == null");
    }
    if (sourceIntent == null) {
        throw new NullPointerException("sourceIntent == null");
    }
    Uri uri = sourceIntent.getData();
    if (uri == null) {
        return createResultAndNotify(activity, false, null, "No Uri in given activity's intent.");
    }
    String uriString = uri.toString();
    DeepLinkEntry entry = findEntry(uriString);
    if (entry != null) {
        DeepLinkUri deepLinkUri = DeepLinkUri.parse(uriString);
        Map<String, String> parameterMap = entry.getParameters(uriString);
        for (String queryParameter : deepLinkUri.queryParameterNames()) {
            for (String queryParameterValue : deepLinkUri.queryParameterValues(queryParameter)) {
                if (parameterMap.containsKey(queryParameter)) {
                    Log.w(TAG, "Duplicate parameter name in path and query param: " + queryParameter);
                }
                parameterMap.put(queryParameter, queryParameterValue);
            }
        }
        parameterMap.put(DeepLink.URI, uri.toString());
        Bundle parameters;
        if (sourceIntent.getExtras() != null) {
            parameters = new Bundle(sourceIntent.getExtras());
        } else {
            parameters = new Bundle();
        }
        for (Map.Entry<String, String> parameterEntry : parameterMap.entrySet()) {
            parameters.putString(parameterEntry.getKey(), parameterEntry.getValue());
        }
        try {
            Class<?> c = entry.getActivityClass();
            Intent newIntent;
            TaskStackBuilder taskStackBuilder = null;
            if (entry.getType() == DeepLinkEntry.Type.CLASS) {
                newIntent = new Intent(activity, c);
            } else {
                Method method;
                try {
                    method = c.getMethod(entry.getMethod(), Context.class);
                    if (method.getReturnType().equals(TaskStackBuilder.class)) {
                        taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity);
                        if (taskStackBuilder.getIntentCount() == 0) {
                            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
                        }
                        newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
                    } else {
                        newIntent = (Intent) method.invoke(c, activity);
                    }
                } catch (NoSuchMethodException exception) {
                    method = c.getMethod(entry.getMethod(), Context.class, Bundle.class);
                    if (method.getReturnType().equals(TaskStackBuilder.class)) {
                        taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity, parameters);
                        if (taskStackBuilder.getIntentCount() == 0) {
                            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
                        }
                        newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
                    } else {
                        newIntent = (Intent) method.invoke(c, activity, parameters);
                    }
                }
            }
            if (newIntent.getAction() == null) {
                newIntent.setAction(sourceIntent.getAction());
            }
            if (newIntent.getData() == null) {
                newIntent.setData(sourceIntent.getData());
            }
            newIntent.putExtras(parameters);
            newIntent.putExtra(DeepLink.IS_DEEP_LINK, true);
            newIntent.putExtra(DeepLink.REFERRER_URI, uri);
            if (activity.getCallingActivity() != null) {
                newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            }
            if (taskStackBuilder != null) {
                taskStackBuilder.startActivities();
            } else {
                activity.startActivity(newIntent);
            }
            return createResultAndNotify(activity, true, uri, null);
        } catch (NoSuchMethodException exception) {
            return createResultAndNotify(activity, false, uri, "Deep link to non-existent method: " + entry.getMethod());
        } catch (IllegalAccessException exception) {
            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
        } catch (InvocationTargetException exception) {
            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
        }
    } else {
        return createResultAndNotify(activity, false, uri, "No registered entity to handle deep link: " + uri.toString());
    }
}
Also used : Context(android.content.Context) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) Bundle(android.os.Bundle) Intent(android.content.Intent) String(java.lang.String) Method(java.lang.reflect.Method) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) Uri(android.net.Uri) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchMethodException(java.lang.NoSuchMethodException) NullPointerException(java.lang.NullPointerException) DeepLinkEntry(com.airbnb.deeplinkdispatch.DeepLinkEntry) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Map(java.util.Map)

Example 3 with String

use of java.lang.String in project MSEC by Tencent.

the class MysqlSink method configure.

@Override
public void configure(Context context) {
    hostname = context.getString("hostname");
    Preconditions.checkNotNull(hostname, "hostname must be set!!");
    port = context.getString("port");
    Preconditions.checkNotNull(port, "port must be set!!");
    databaseName = context.getString("databaseName");
    Preconditions.checkNotNull(databaseName, "databaseName must be set!!");
    tablePrefix = context.getString("tableprefix");
    Preconditions.checkNotNull(tablePrefix, "tableprefix must be set!!");
    user = context.getString("user");
    Preconditions.checkNotNull(user, "user must be set!!");
    password = context.getString("password");
    if (password == null)
        password = "";
    //Preconditions.checkNotNull(password, "password must be set!!");
    batchSize = context.getInteger("batchSize", 100);
    Preconditions.checkNotNull(batchSize > 0, "batchSize must be a positive number!!");
    maxContentLength = context.getInteger("maxContentLength", 1000);
    Preconditions.checkNotNull(maxContentLength > 0, "maxContentLength must be a positive number!!");
    String directory = context.getString("directory");
    String rollInterval = context.getString("loadInterval");
    createTableSqlFile = context.getString("create_table_sql");
    Preconditions.checkArgument(directory != null, "Directory may not be null");
    Preconditions.checkNotNull(createTableSqlFile, "create table sql must be set!!");
    if (rollInterval == null) {
        this.rollInterval = defaultRollInterval;
    } else {
        this.rollInterval = Long.parseLong(rollInterval);
    }
    Preconditions.checkArgument(this.rollInterval > 0, "rollInterval must be positive");
    this.directory = new File(directory);
    tableName = "";
}
Also used : String(java.lang.String) File(java.io.File)

Example 4 with String

use of java.lang.String in project MSEC by Tencent.

the class MysqlSink method doSerialize.

private void doSerialize(Event event) throws IOException {
    Map<String, String> headers;
    String content = "";
    headers = event.getHeaders();
    if (outputStream == null) {
        LOG.error("Null stream for Mysql sink serialization!");
        return;
    }
    for (String column : columnList) {
        if (column.compareTo("content") == 0) {
            continue;
        }
        if (headers.containsKey(column)) {
            outputStream.write((headers.get(column) + "\t").getBytes());
            headers.remove(column);
        } else if (column.compareTo("instime") == 0) {
            Timestamp timestamp = new Timestamp(new Date().getTime());
            outputStream.write((timestamp.toString() + "\t").getBytes());
        } else {
            //default value
            outputStream.write("\t".getBytes());
        }
    }
    for (String headerKey : headers.keySet()) {
        String headerValue = headers.get(headerKey);
        if (headerValue != null && !headerValue.isEmpty()) {
            content += headerKey + "=" + headerValue + " ";
        }
    }
    content += new String(event.getBody());
    content = content.replace('\t', ' ').replace('\n', ' ');
    if (content.length() > maxContentLength) {
        content = content.substring(0, maxContentLength - 15) + "<..truncated..>";
    }
    outputStream.write((content + "\n").getBytes());
    LOG.info("Mysql sink process: " + content + " " + headers.get("IP") + " " + headers.get("Level") + " " + headers.get("RPCName"));
}
Also used : String(java.lang.String) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 5 with String

use of java.lang.String in project MSEC by Tencent.

the class MysqlSink method createTable.

private int createTable() throws IOException, SQLException {
    SimpleDateFormat formatter = new SimpleDateFormat("MMdd");
    String curTableName = "t_dailylog_" + formatter.format(new Date());
    if (curTableName.compareTo(tableName) == 0) {
        return 0;
    }
    DatabaseMetaData md = conn.getMetaData();
    ResultSet rs = md.getTables(null, null, curTableName, null);
    if (rs.next()) {
        tableName = curTableName;
        return 1;
    }
    //create table
    File file = new File(createTableSqlFile);
    BufferedReader bf = new BufferedReader(new FileReader(file));
    StringBuilder sb = new StringBuilder();
    String line = "";
    while (line != null) {
        line = bf.readLine();
        if (line == null)
            break;
        sb.append(line);
    }
    String createTableSql = sb.toString().replace("$TABLENAME$", curTableName);
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(createTableSql);
    LOG.info("Create table " + curTableName + " using sql statement: " + createTableSql);
    tableName = curTableName;
    return 2;
}
Also used : StringBuilder(java.lang.StringBuilder) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) String(java.lang.String) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date)

Aggregations

String (java.lang.String)350 Override (java.lang.Override)42 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)29 HttpPartSchema (org.apache.juneau.httppart.HttpPartSchema)24 ResultSet (java.sql.ResultSet)23 HashMap (java.util.HashMap)22 PreparedStatement (java.sql.PreparedStatement)20 JsonParseException (org.bson.json.JsonParseException)19 IOException (java.io.IOException)16 SQLException (java.sql.SQLException)16 Statement (java.sql.Statement)13 KeyValueMap (android.filterfw.core.KeyValueMap)12 GraphIOException (android.filterfw.io.GraphIOException)12 Object (java.lang.Object)12 List (java.util.List)12 Map (java.util.Map)12 Pattern (java.util.regex.Pattern)12 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)12 Exception (java.lang.Exception)11