Example usage for java.text ParseException getMessage

List of usage examples for java.text ParseException getMessage

Introduction

In this page you can find the example usage for java.text ParseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java

/**
 * Gets the known username history of a UUID. All dates are in UTC.
 * This returns a map of player names and when they were last seen (the
 * approximate date they stopped using that name).
 *
 * @param uuid the uuid to lookup, cannot be null
 *
 * @return a map of names and dates (UTC), or an empty map for invalid input or unknown/non-existent history
 *//*from w  w  w . ja  v  a  2s .c  om*/
public static Map<String, Date> getHistory(UUID uuid) {
    if (uuid == null)
        return new HashMap<>();
    try {
        URL url = new URL("http://uuid.turt2live.com/history/" + uuid.toString().replaceAll("-", ""));
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String parsed = "";
        String line;
        while ((line = reader.readLine()) != null)
            parsed += line;
        reader.close();

        Map<String, Date> map = new HashMap<>();
        Object o = JSONValue.parse(parsed);
        if (o instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) o;
            Object namesObj = jsonObject.get("names");
            if (namesObj instanceof JSONArray) {
                JSONArray names = (JSONArray) namesObj;
                for (Object name : names) {
                    o = name;
                    if (o instanceof JSONObject) {
                        JSONObject json = (JSONObject) o;

                        Object nameObj = json.get("name");
                        Object dateObj = json.get("last-seen");
                        if (nameObj instanceof String && dateObj instanceof String) {
                            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                            format.setTimeZone(TimeZone.getTimeZone("UTC"));
                            try {
                                Date date = format.parse((String) dateObj);
                                map.put((String) nameObj, date);
                            } catch (ParseException e) {
                                System.out.println("Could not parse " + dateObj + ": " + e.getMessage());
                            }
                        }
                    }
                }
            }
        }
        return map;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new HashMap<>();
}

From source file:at.newsagg.utils.ParserUtils.java

/**
 * Tries different date formats to parse against the given string
 * representation to retrieve a valid Date object.
 *///from w  ww.ja va 2  s.  c  o  m
public static Date getDateOLD(String strdate) {
    Date result = null;

    try {
        result = dfA.parse(strdate);
    } catch (java.text.ParseException eA) {
        logger.warn("Error parsing date (A): " + eA.getMessage());
        try {
            result = dfB.parse(strdate);
        } catch (java.text.ParseException eB) {
            logger.warn("Error parsing date (B): " + eB.getMessage());
            try {
                result = dfC.parse(strdate);
                // try to retrieve the timezone anyway
                result = extractTimeZone(strdate, result);
            } catch (java.text.ParseException eC) {
                logger.warn("Error parsing date (C): " + eC.getMessage());
                try {
                    result = dfD.parse(strdate);
                } catch (java.text.ParseException eD) {
                    logger.warn("Error parsing date (D): " + eD.getMessage());
                    eD.printStackTrace();
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Parsing date '" + strdate + "' resulted in: " + result);
    }
    if (result == null) {
        logger.warn("No appropiate date could be extracted from " + strdate);

    }
    return result;
}

From source file:com.hybris.datahub.outbound.utils.CommonUtils.java

/**
 * Get all dates within three months/*from w ww.ja  v  a  2  s .c o  m*/
 *
 * @param startDate
 * @param nowDate
 *
 * @return Sample Data:
 *         <p>
 *         key:value-->start:2001-01-01 00:00:00 <br>
 *         or <br>
 *         end:2001-01-01 23:59:59 <br>
 */
public static List<Map<String, Date>> findDates(Date startDate, Date nowDate) {
    final List<Map<String, Date>> lDate = new ArrayList<Map<String, Date>>();
    final SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
    final SimpleDateFormat ymdmhs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    final Calendar calendar = Calendar.getInstance();
    if (nowDate == null && startDate == null) {

        nowDate = calendar.getTime();
        calendar.add(Calendar.MONTH, -3);
        startDate = calendar.getTime();
    } else if (nowDate != null && startDate == null) {

        calendar.add(Calendar.MONTH, -3);
        startDate = calendar.getTime();

    } else if (nowDate == null && startDate != null) {
        nowDate = calendar.getTime();
    }

    try {
        final Map<String, Date> beginItem = new HashMap<String, Date>();
        beginItem.put("start", ymdmhs.parse(ymd.format(startDate) + " 00:00:00"));
        beginItem.put("end", ymdmhs.parse(ymd.format(startDate) + " 23:59:59"));

        lDate.add(beginItem);

        final Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(startDate);

        final Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(startDate);

        while (ymd.parse(ymd.format(nowDate)).after(calBegin.getTime())) {
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            final Map<String, Date> dateItem = new HashMap<String, Date>();

            dateItem.put("start", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 00:00:00"));
            dateItem.put("end", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 23:59:59"));

            lDate.add(dateItem);
        }
    } catch (final ParseException e) {
        LOGGER.error(e.getMessage());
    }
    return lDate;
}

From source file:com.arvato.thoroughly.util.CommonUtils.java

/**
 * Get all dates within three months/*from   w  ww. j a v  a2  s.  co m*/
 *
 * @param startDate
 * @param nowDate
 *
 * @return Sample Data:
 *         <p>
 *         key:value-->start:2001-01-01 00:00:00 <br>
 *         or <br>
 *         end:2001-01-01 23:59:59 <br>
 */
public static List<Map<String, Date>> findDates(Date startDate, Date nowDate) {
    List<Map<String, Date>> lDate = new ArrayList<Map<String, Date>>();
    SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    SimpleDateFormat ymdmhs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);

    Calendar calendar = Calendar.getInstance();
    if (nowDate == null && startDate == null) {

        nowDate = calendar.getTime();
        calendar.add(Calendar.MONTH, -3);
        startDate = calendar.getTime();
    } else if (nowDate != null && startDate == null) {

        calendar.add(Calendar.MONTH, -3);
        startDate = calendar.getTime();

    } else if (nowDate == null && startDate != null) {
        nowDate = calendar.getTime();
    }

    try {
        Map<String, Date> beginItem = new HashMap<String, Date>();
        beginItem.put("start", ymdmhs.parse(ymd.format(startDate) + " 00:00:00"));
        beginItem.put("end", ymdmhs.parse(ymd.format(startDate) + " 23:59:59"));

        lDate.add(beginItem);

        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(startDate);

        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(startDate);

        while (ymd.parse(ymd.format(nowDate)).after(calBegin.getTime())) {
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            Map<String, Date> dateItem = new HashMap<String, Date>();

            dateItem.put("start", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 00:00:00"));
            dateItem.put("end", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 23:59:59"));

            lDate.add(dateItem);
        }
    } catch (ParseException e) {
        LOGGER.error(e.getMessage());
    }
    return lDate;
}

From source file:net.kamhon.ieagle.util.DateUtil.java

public static Date getDate(String d, String format) {
    SimpleDateFormat df = new SimpleDateFormat(format);
    try {//  w  ww  . ja v a2 s.  c  o m
        return df.parse(d);
    } catch (ParseException e) {
        throw new ValidatorException(e.getMessage());
    }
}

From source file:com.gisgraphy.util.DateUtil.java

/**
 * This method converts a String to a date using the datePattern
 * /*from w  w  w  .ja v a 2s.com*/
 * @param strDate
 *                the date to convert (in format MM/dd/yyyy)
 * @return a date object
 * @throws ParseException
 *                 when String doesn't match the expected format
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + getDatePattern());
        }

        aDate = convertStringToDate(getDatePattern(), strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());
    }

    return aDate;
}

From source file:com.teamsun.framework.util.DateUtil.java

/**
 * This method converts a String to a date using the datePattern
 * /*from   w  w w. j  a v  a 2 s .  c  o m*/
 * @param strDate the date to convert (in format yyyy-MM-dd)
 * @return a date object
 * 
 * @throws ParseException
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + datePattern);
        }

        aDate = convertStringToDate(datePattern, strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        pe.printStackTrace();
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());

    }

    return aDate;
}

From source file:net.iaeste.iws.core.transformers.CSVTransformer.java

private static Date convertDate(final Map<String, String> errors, final OfferFields field,
        final CSVRecord record) {
    final String value = record.get(field.getField());
    Date result = null;//from   w ww. j a v a  2 s. c o  m

    if ((value != null) && !value.isEmpty()) {
        try {
            final DateFormat formatter = new SimpleDateFormat(DATE_FORMAT, DEFAULT_LOCALE);
            result = new Date(formatter.parse(value));
        } catch (ParseException e) {
            LOG.debug(e.getMessage(), e);
            errors.put(field.getField(), e.getMessage());
        }
    }

    return result;
}

From source file:org.openhie.openempi.util.DateUtil.java

/**
 * This method converts a String to a date using the datePattern
 * /*from   w w w  . j  a v  a 2 s  .  c om*/
 * @param strDate the date to convert (in format MM/dd/yyyy)
 * @return a date object
 * @throws ParseException when String doesn't match the expected format
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + getDatePattern());
        }

        aDate = convertStringToDate(getDatePattern(), strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        pe.printStackTrace();
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());
    }

    return aDate;
}

From source file:com.krawler.common.util.SchedulingUtilities.java

public static Date getDate(String date) {
    Date d = null;/* w  w  w  .j av a 2  s. co  m*/
    try {
        d = DateUtils.parseDate(date, new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" });
    } catch (ParseException e) {
        throw ServiceException.FAILURE("Date Parse Exception :: " + e.getMessage(), e);
    } finally {
        return d;
    }
}