Example usage for java.text ParseException printStackTrace

List of usage examples for java.text ParseException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:net.naijatek.myalumni.util.date.DateConverterUtil.java

/**
 * This method converts a String to a date using the datePattern
 * //  w w w .  j  a v  a 2s . c  om
 * @param strDate the date to convert (in format MM/dd/yyyy)
 * @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: " + 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:gobblin.source.extractor.utils.Utils.java

public static Date toDate(long value, String format) {
    SimpleDateFormat fmt = new SimpleDateFormat(format);
    Date date = null;//  ww w  .j a v a  2s  .  c  o m
    try {
        date = fmt.parse(Long.toString(value));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:gobblin.source.extractor.utils.Utils.java

public static String toDateTimeFormat(String input, String inputfmt, String outputfmt) {
    Date date = null;//from  w w w  .  j av a 2s  . co m
    SimpleDateFormat infmt = new SimpleDateFormat(inputfmt);
    try {
        date = infmt.parse(input);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    SimpleDateFormat outFormat = new SimpleDateFormat(outputfmt);
    return outFormat.format(date);
}

From source file:gobblin.source.extractor.utils.Utils.java

public static Date toDate(Date date, String format) {
    SimpleDateFormat fmt = new SimpleDateFormat(format);
    String dateStr = fmt.format(date);
    Date outDate = null;/* www.ja va2  s  . c o  m*/
    try {
        outDate = fmt.parse(dateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return outDate;
}

From source file:com.jiangyifen.ec2.globaldata.license.LicenseManager.java

/**
 * license/*from   ww  w. ja va 2 s .c  o m*/
 * 
 * @param localmd5
 * @param mac
 * @param date
 * @param count
 * @return
 */
private static Boolean licenseValidate(String localmd5, String mac, String date, String count) {
    // ?md5 ??
    localmd5 = StringUtils.trimToEmpty(localmd5);

    // ?
    mac = StringUtils.trimToEmpty(mac);
    date = StringUtils.trimToEmpty(date);
    count = StringUtils.trimToEmpty(count);

    // mac?date?count??
    Boolean isWellformat = regexMatchCheck(mac, date, count);
    if (isWellformat) {
        //continue
    } else {
        return false;
    }

    // 32?md5 
    String saltedLicense = mac + LicenseManager.LICENSE_SALT + date + count;
    String bit32_md5_result = bit32_md5(saltedLicense);

    // ?
    if (localmd5.equals(bit32_md5_result)) {
        //?
        //         LicenseManager.LICENSE_DATE
        try {
            Date expiredate = simpleDateFormat.parse(date);
            if (new Date().after(expiredate)) {
                logger.warn("chb: License expires, license expiredate is " + date);
                return false;
            }
        } catch (ParseException e) {
            e.printStackTrace();
            logger.warn("chb: License date parse exception");
            return false;
        }
        return true;
    } else {
        logger.warn("chb: License and bit32_md5_result not match , changed !!!");
        return false;
    }
}

From source file:edu.duke.cabig.c3pr.utils.StringUtils.java

public static Date convertToDate(String dateString, String format) {

    if (dateString == null || dateString.length() == 0)
        return null;

    SimpleDateFormat sdf;/* w w  w.jav  a2s . co  m*/
    boolean defaultFlag = false;
    if (format != null && format.length() > 0) {
        sdf = new SimpleDateFormat(format);
    } else {
        sdf = new SimpleDateFormat("MM/dd/yyyy");
        defaultFlag = true;
    }

    try {
        return sdf.parse(dateString);
    } catch (ParseException e) {
        if (defaultFlag)
            try {
                return (new SimpleDateFormat("MM-dd-yyyy")).parse(dateString);
            } catch (ParseException e1) {
                // TODO add better error logging here
                e1.printStackTrace();
            }
        else {
            e.printStackTrace(); // TODO add better error logging here
        }
    }

    return null;

}

From source file:de.tudarmstadt.ukp.lmf.transform.germanet.InterlingualIndexConverter.java

public static MetaData getDefaultMetaData() {
    /*/*from   ww  w .  j  a  v a  2 s .  c  o  m*/
     * Generate Metadata
     */
    MetaData m = new MetaData();
    m.setAutomatic(false);
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Date creationDate;
    try {
        creationDate = formatter.parse("2014-04-01");
        m.setCreationDate(creationDate);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    m.setCreationProcess("semi-automatic");
    m.setCreationTool("http://www.sfs.uni-tuebingen.de/GermaNet/ili.shtml");
    m.setVersion("GN 9.0");
    m.setId("GNWN_ILI_0");//TODO
    return m;
}

From source file:POP3Mail.java

public static final boolean printMessageInfo(BufferedReader reader, int id, PrintWriter printWriter)
        throws IOException {
    String from = "";
    String subject = "";
    String received = "";
    String to = "";
    String replyto = "";
    String date = "";
    String line = null;//from  w ww.  j a  va  2s  .  co m
    Date d = null;
    Date dd = null;
    try {
        dd = dateformat.parse("01 Jan 2020 00:00:00");
    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    while (true) {
        if (line == null) {
            line = reader.readLine();
        }
        if (line == null) {
            break;
        }
        String lower = line.toLowerCase(Locale.ENGLISH);
        System.out.println(line);
        if (lower.startsWith("from: ")) {
            from = line.substring(6).trim();
            line = null;
        } else if (lower.startsWith("reply-to: ")) {
            replyto = line.substring("reply-to: ".length()).trim();
            line = null;
        } else if (lower.startsWith("to: ")) {
            to = line.substring(3).trim();
            while ((line = reader.readLine()) != null) {
                lower = line.toLowerCase(Locale.ENGLISH);
                if (line.startsWith(" ")) {
                    to += line;
                } else {
                    break;
                }
            }

        } else if (lower.startsWith("subject: ")) {
            subject = line.substring(9).trim();
            line = null;
        } else if (lower.startsWith("date: ")) {
            date = line.substring("date: ".length()).trim();
            try {
                date = date.split(",")[1].trim();
                String[] tokens = date.split(" ");
                d = dateformat.parse(tokens[0] + " " + tokens[1] + " " + tokens[2] + " " + tokens[3]);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            line = null;
        } else {
            line = null;
        }
    }
    if (d != null && d.before(dd)) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", id);
        jsonObject.put("to", to);
        jsonObject.put("from", from);
        String[] t = parseTo(to);
        jsonObject.put("tolist", Arrays.asList(t));
        String ttt = "";
        for (String tt : t) {
            ttt += "," + tt;
        }
        String[] f = parseTo(from);
        String fff = "";
        for (String ff : f) {
            fff += "," + ff;
        }
        jsonObject.put("fromlist", Arrays.asList(f));
        jsonObject.put("subject", subject);
        jsonObject.put("date", date);
        jsonObject.put("time", d.getTime());
        jsonObject.put("reply-to", replyto);
        FileWriter fileWriter = new FileWriter(String.format("../json/%05d.json", id));
        jsonObject.write(fileWriter);
        fileWriter.close();
        printWriter.println(
                String.format("%d,'%s','%s','%s','%s','%s','%s','%s',%d", id, escape(from), fff.substring(1),
                        escape(to), ttt.substring(1), escape(replyto), escape(subject), date, d.getTime()));
        return true;

    }
    return false;
}

From source file:com.jiangyifen.ec2.globaldata.license.LicenseManagerMain.java

/**
 * license//from   w  w  w .  j av a2s .c  o m
 * 
 * @param localmd5
 * @param mac
 * @param date
 * @param count
 * @return
 */
private static Boolean licenseValidate(String localmd5, String mac, String date, String count) {
    // ?md5 ??
    localmd5 = StringUtils.trimToEmpty(localmd5);

    // ?
    mac = StringUtils.trimToEmpty(mac);
    date = StringUtils.trimToEmpty(date);
    count = StringUtils.trimToEmpty(count);

    // mac?date?count??
    Boolean isWellformat = regexMatchCheck(mac, date, count);
    if (isWellformat) {
        // continue
    } else {
        return false;
    }

    // 32?md5 
    String saltedLicense = mac + LicenseManagerMain.LICENSE_SALT + date + count;
    String bit32_md5_result = bit32_md5(saltedLicense);

    // ?
    if (localmd5.equals(bit32_md5_result)) {
        // ?
        // LicenseManager.LICENSE_DATE
        try {
            Date expiredate = simpleDateFormat.parse(date);
            if (new Date().after(expiredate)) {
                logger.warn("chb: License expires, license expiredate is " + date);
                return false;
            }
        } catch (ParseException e) {
            e.printStackTrace();
            logger.warn("chb: License date parse exception");
            return false;
        }
        return true;
    } else {
        logger.warn("chb: License and bit32_md5_result not match , changed !!!");
        return false;
    }
}

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 w w.ja  va 2  s.c  om*/
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;
}