Search in sources :

Example 61 with ParseException

use of java.text.ParseException in project aerosolve by airbnb.

the class DateDiffTransform method doTransform.

@Override
public void doTransform(FeatureVector featureVector) {
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    Map<String, Map<String, Double>> floatFeatures = featureVector.getFloatFeatures();
    if (stringFeatures == null || floatFeatures == null) {
        return;
    }
    Set<String> feature1 = stringFeatures.get(fieldName1);
    Set<String> feature2 = stringFeatures.get(fieldName2);
    if (feature1 == null || feature2 == null) {
        return;
    }
    Map<String, Double> output = Util.getOrCreateFloatFeature(outputName, floatFeatures);
    try {
        for (String endDateStr : feature1) {
            Date endDate = format.parse(endDateStr);
            for (String startDateStr : feature2) {
                Date startDate = format.parse(startDateStr);
                long diff = endDate.getTime() - startDate.getTime();
                long diffDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
                output.put(endDateStr + "-m-" + startDateStr, (double) diffDays);
            }
        }
    } catch (ParseException e) {
        e.printStackTrace();
        return;
    }
}
Also used : Set(java.util.Set) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date)

Example 62 with ParseException

use of java.text.ParseException in project DataX by alibaba.

the class NormalTask method getVersion.

public long getVersion(Record record) {
    int index = versionColumn.getInt(Key.INDEX);
    long timestamp;
    if (index == -1) {
        //指定时间作为版本
        timestamp = versionColumn.getLong(Key.VALUE);
        if (timestamp < 0) {
            throw DataXException.asDataXException(Hbase094xWriterErrorCode.CONSTRUCT_VERSION_ERROR, "您指定的版本非法!");
        }
    } else {
        //指定列作为版本,long/doubleColumn直接record.aslong, 其它类型尝试用yyyy-MM-dd HH:mm:ss,yyyy-MM-dd HH:mm:ss SSS去format
        if (index >= record.getColumnNumber()) {
            throw DataXException.asDataXException(Hbase094xWriterErrorCode.CONSTRUCT_VERSION_ERROR, String.format("您的versionColumn配置项中中index值超出范围,根据reader端配置,index的值小于%s,而您配置的值为%s,请检查并修改.", record.getColumnNumber(), index));
        }
        if (record.getColumn(index).getRawData() == null) {
            throw DataXException.asDataXException(Hbase094xWriterErrorCode.CONSTRUCT_VERSION_ERROR, "您指定的版本为空!");
        }
        SimpleDateFormat df_senconds = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat df_ms = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        if (record.getColumn(index) instanceof LongColumn || record.getColumn(index) instanceof DoubleColumn) {
            timestamp = record.getColumn(index).asLong();
        } else {
            Date date;
            try {
                date = df_ms.parse(record.getColumn(index).asString());
            } catch (ParseException e) {
                try {
                    date = df_senconds.parse(record.getColumn(index).asString());
                } catch (ParseException e1) {
                    LOG.info(String.format("您指定第[%s]列作为hbase写入版本,但在尝试用yyyy-MM-dd HH:mm:ss 和 yyyy-MM-dd HH:mm:ss SSS 去解析为Date时均出错,请检查并修改", index));
                    throw DataXException.asDataXException(Hbase094xWriterErrorCode.CONSTRUCT_VERSION_ERROR, e1);
                }
            }
            timestamp = date.getTime();
        }
    }
    return timestamp;
}
Also used : LongColumn(com.alibaba.datax.common.element.LongColumn) DoubleColumn(com.alibaba.datax.common.element.DoubleColumn) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 63 with ParseException

use of java.text.ParseException in project dubbo by alibaba.

the class Routes method show.

/**
     * 显示路由详细信息
     * @param context
     */
public void show(Map<String, Object> context) {
    try {
        Route route = routeService.findRoute(Long.parseLong((String) context.get("id")));
        if (route == null) {
            throw new IllegalArgumentException("The route is not existed.");
        }
        if (route.getService() != null && !route.getService().isEmpty()) {
            context.put("service", route.getService());
        }
        RouteRule routeRule = RouteRule.parse(route);
        @SuppressWarnings("unchecked") Map<String, RouteRule.MatchPair>[] paramArray = new Map[] { routeRule.getWhenCondition(), routeRule.getThenCondition() };
        String[][][] namesArray = new String[][][] { when_names, then_names };
        for (int i = 0; i < paramArray.length; ++i) {
            Map<String, RouteRule.MatchPair> param = paramArray[i];
            String[][] names = namesArray[i];
            for (String[] name : names) {
                RouteRule.MatchPair matchPair = param.get(name[0]);
                if (matchPair == null) {
                    continue;
                }
                if (!matchPair.getMatches().isEmpty()) {
                    String m = RouteRule.join(matchPair.getMatches());
                    context.put(name[1], m);
                }
                if (!matchPair.getUnmatches().isEmpty()) {
                    String u = RouteRule.join(matchPair.getUnmatches());
                    context.put(name[2], u);
                }
            }
        }
        context.put("route", route);
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(route.getService()))));
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) RouteRule(com.alibaba.dubbo.registry.common.route.RouteRule) ParseException(java.text.ParseException) HashMap(java.util.HashMap) Map(java.util.Map) Route(com.alibaba.dubbo.registry.common.domain.Route)

Example 64 with ParseException

use of java.text.ParseException in project dubbo by alibaba.

the class Tool method isInBlackList.

public boolean isInBlackList(Consumer consumer) {
    String service = consumer.getService();
    List<Route> routes = routeService.findForceRouteByService(service);
    if (routes == null || routes.size() == 0) {
        return false;
    }
    String ip = getIP(consumer.getAddress());
    for (Route route : routes) {
        try {
            if (!route.isEnabled()) {
                continue;
            }
            String filterRule = route.getFilterRule();
            if (filterRule == null || filterRule.length() == 0 || "false".equals(filterRule)) {
                Map<String, MatchPair> rule = RouteRule.parseRule(route.getMatchRule());
                MatchPair pair = rule.get("consumer.host");
                if (pair == null) {
                    pair = rule.get("host");
                }
                if (pair != null) {
                    if (pair.getMatches() != null && pair.getMatches().size() > 0) {
                        for (String host : pair.getMatches()) {
                            if (ParseUtils.isMatchGlobPattern(host, ip)) {
                                return true;
                            }
                        }
                    }
                    if (pair.getUnmatches() != null && pair.getUnmatches().size() > 0) {
                        boolean forbid = true;
                        for (String host : pair.getUnmatches()) {
                            if (ParseUtils.isMatchGlobPattern(host, ip)) {
                                forbid = false;
                            }
                        }
                        if (forbid) {
                            return true;
                        }
                    }
                }
            }
        } catch (ParseException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return false;
}
Also used : MatchPair(com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair) ParseException(java.text.ParseException) Route(com.alibaba.dubbo.registry.common.domain.Route)

Example 65 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class SipManager method getFromHeader.

public FromHeader getFromHeader(boolean isNew) throws CommunicationsException {
    if (fromHeader != null && !isNew) {
        return fromHeader;
    }
    try {
        SipURI fromURI = (SipURI) addressFactory.createURI(currentlyUsedURI);
        fromURI.setTransportParam(listeningPoint.getTransport());
        fromURI.setPort(listeningPoint.getPort());
        Address fromAddress = addressFactory.createAddress(fromURI);
        if (displayName != null && displayName.trim().length() > 0) {
            fromAddress.setDisplayName(displayName);
        } else {
            fromAddress.setDisplayName(// UserCredentials.getUser());
            UserCredentials.getUserDisplay());
        // JOptionPane.showMessageDialog(null,currentlyUsedURI);
        }
        fromHeader = headerFactory.createFromHeader(fromAddress, Integer.toString(hashCode()));
    } catch (ParseException ex) {
        throw new CommunicationsException("A ParseException occurred while creating From Header!", ex);
    }
    return fromHeader;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Aggregations

ParseException (java.text.ParseException)1141 Date (java.util.Date)435 SimpleDateFormat (java.text.SimpleDateFormat)387 IOException (java.io.IOException)118 DateFormat (java.text.DateFormat)117 Calendar (java.util.Calendar)104 ArrayList (java.util.ArrayList)98 Test (org.junit.Test)58 HashMap (java.util.HashMap)45 Matcher (java.util.regex.Matcher)39 File (java.io.File)38 GregorianCalendar (java.util.GregorianCalendar)34 Map (java.util.Map)28 BigDecimal (java.math.BigDecimal)23 Timestamp (java.sql.Timestamp)21 List (java.util.List)21 Locale (java.util.Locale)20 SipException (javax.sip.SipException)20 InputStream (java.io.InputStream)19 TimeZone (java.util.TimeZone)19