Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

In this page you can find the example usage for java.lang NumberFormatException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

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

static void transformInteger(final Map<String, String> errors, final Verifiable obj, final OfferFields field,
        final CSVRecord record) {
    final String value = record.get(field.getField());

    if ((value != null) && !value.isEmpty()) {
        try {//from   w w  w  .j a va  2  s . co m
            final Integer number = Integer.valueOf(value);
            invokeMethodOnObject(errors, obj, field, number);
        } catch (NumberFormatException e) {
            LOG.debug(e.getMessage(), e);
            errors.put(field.getField(), e.getMessage());
        }
    }
}

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

static void transformBigDecimal(final Map<String, String> errors, final Verifiable obj, final OfferFields field,
        final CSVRecord record) {
    final String value = record.get(field.getField());

    if ((value != null) && !value.isEmpty()) {
        try {//from  w  w w  . j a v  a 2 s .  c o m
            final BigDecimal number = new BigDecimal(value);
            invokeMethodOnObject(errors, obj, field, number);
        } catch (NumberFormatException e) {
            LOG.debug(e.getMessage(), e);
            errors.put(field.getField(), e.getMessage());
        }
    }
}

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

static void transformFloat(final Map<String, String> errors, final Verifiable obj, final OfferFields field,
        final CSVRecord record) {
    final String value = record.get(field.getField());

    if ((value != null) && !value.isEmpty()) {
        try {//from w w w .jav a 2s.c o  m
            final Float number = Float.valueOf(value);
            invokeMethodOnObject(errors, obj, field, number);
        } catch (NumberFormatException e) {
            LOG.debug(e.getMessage(), e);
            errors.put(field.getField(), e.getMessage());
        }
    }
}

From source file:com.rabbitframework.commons.utils.StringUtils.java

public static int stringToInt(String value, int defaultValue) {
    int result = defaultValue;
    if (isEmpty(value)) {
        return result;
    }//w  ww  .j a va  2 s  .c  o  m
    try {
        result = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        logger.error(e.getMessage(), e);
    }
    return result;
}

From source file:com.rabbitframework.commons.utils.StringUtils.java

public static long stringToLong(String value, long defaultValue) {
    Long result = defaultValue;/* w  w w  .ja  va  2  s .  co  m*/
    if (isEmpty(value)) {
        return result;
    }
    try {
        result = Long.parseLong(value);
    } catch (NumberFormatException e) {
        logger.error(e.getMessage(), e);
    }
    return result;
}

From source file:controllers.api.v1.Metric.java

public static Result getPagedMetricsByDashboard(String dashboardName) {

    ObjectNode result = Json.newObject();
    String username = session("user");

    int page = 1;
    String pageStr = request().getQueryString("page");
    if (StringUtils.isBlank(pageStr)) {
        page = 1;/*from   w  w  w.  jav  a  2 s  .c  o m*/
    } else {
        try {
            page = Integer.parseInt(pageStr);
        } catch (NumberFormatException e) {
            Logger.warn("Metric Controller getPagedMetricsByDashboard wrong page parameter. Error message: "
                    + e.getMessage());
            page = 1;
        }
    }

    int size = 10;
    String sizeStr = request().getQueryString("size");
    if (StringUtils.isBlank(sizeStr)) {
        size = 10;
    } else {
        try {
            size = Integer.parseInt(sizeStr);
        } catch (NumberFormatException e) {
            Logger.warn("Metric Controller getPagedMetricsByDashboard wrong size parameter. Error message: "
                    + e.getMessage());
            size = 10;
        }
    }

    result.put("status", "ok");
    result.set("data", MetricsDAO.getPagedMetrics(dashboardName, "", page, size, username));
    return ok(result);
}

From source file:DateParser.java

private static Calendar getCalendar(String isodate) {
    // YYYY-MM-DDThh:mm:ss.sTZD
    StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true);

    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.clear();//ww  w . j  a  v  a2s  . c o  m
    try {
        // Year
        if (st.hasMoreTokens()) {
            int year = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.YEAR, year);
        } else {
            return calendar;
        }
        // Month
        if (check(st, "-") && (st.hasMoreTokens())) {
            int month = Integer.parseInt(st.nextToken()) - 1;
            calendar.set(Calendar.MONTH, month);
        } else {
            return calendar;
        }
        // Day
        if (check(st, "-") && (st.hasMoreTokens())) {
            int day = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.DAY_OF_MONTH, day);
        } else {
            return calendar;
        }
        // Hour
        if (check(st, "T") && (st.hasMoreTokens())) {
            int hour = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.HOUR_OF_DAY, hour);
        } else {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
        // Minutes
        if (check(st, ":") && (st.hasMoreTokens())) {
            int minutes = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.MINUTE, minutes);
        } else {
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }

        //
        // Not mandatory now
        //

        // Secondes
        if (!st.hasMoreTokens()) {
            return calendar;
        }
        String tok = st.nextToken();
        if (tok.equals(":")) { // secondes
            if (st.hasMoreTokens()) {
                int secondes = Integer.parseInt(st.nextToken());
                calendar.set(Calendar.SECOND, secondes);
                if (!st.hasMoreTokens()) {
                    return calendar;
                }
                // frac sec
                tok = st.nextToken();
                if (tok.equals(".")) {
                    // bug fixed, thx to Martin Bottcher
                    String nt = st.nextToken();
                    while (nt.length() < 3) {
                        nt += "0";
                    }
                    nt = nt.substring(0, 3); // Cut trailing chars..
                    int millisec = Integer.parseInt(nt);
                    // int millisec = Integer.parseInt(st.nextToken()) * 10;
                    calendar.set(Calendar.MILLISECOND, millisec);
                    if (!st.hasMoreTokens()) {
                        return calendar;
                    }
                    tok = st.nextToken();
                } else {
                    calendar.set(Calendar.MILLISECOND, 0);
                }
            } else {
                throw new RuntimeException("No secondes specified");
            }
        } else {
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
        }
        // Timezone
        if (!tok.equals("Z")) { // UTC
            if (!(tok.equals("+") || tok.equals("-"))) {
                throw new RuntimeException("only Z, + or - allowed");
            }
            boolean plus = tok.equals("+");
            if (!st.hasMoreTokens()) {
                throw new RuntimeException("Missing hour field");
            }
            int tzhour = Integer.parseInt(st.nextToken());
            int tzmin = 0;
            if (check(st, ":") && (st.hasMoreTokens())) {
                tzmin = Integer.parseInt(st.nextToken());
            } else {
                throw new RuntimeException("Missing minute field");
            }
            if (plus) {
                calendar.add(Calendar.HOUR, -tzhour);
                calendar.add(Calendar.MINUTE, -tzmin);
            } else {
                calendar.add(Calendar.HOUR, tzhour);
                calendar.add(Calendar.MINUTE, tzmin);
            }
        }
    } catch (NumberFormatException ex) {
        throw new RuntimeException("[" + ex.getMessage() + "] is not an integer");
    }
    return calendar;
}

From source file:com.github.gagu.web.util.Log4jWebConfigurer.java

/**
 * Initialize log4j, including setting the web app root system property.
 * @param servletContext the current ServletContext
 * @see WebUtils#setWebAppRootSystemProperty
 *///from ww  w .  ja  v  a  2 s .co m
public static void initLogging(ServletContext servletContext) {
    // Expose the web app root system property.
    if (exposeWebAppRoot(servletContext)) {
        WebUtils.setWebAppRootSystemProperty(servletContext);
    }

    // Only perform custom log4j initialization in case of a config file.
    // e.g. "/WEB-INF/config/log4j.properties"
    String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
    //TODO load default log4j.xml specified
    if (StringUtils.isEmpty(location)) {
        location = "com/github/gagu/web/util/framework-log4j.xml";
    }

    if (location != null) {
        // Perform actual log4j initialization; else rely on log4j's default initialization.
        try {
            // Resolve property placeholders before potentially resolving a real path.
            location = ServletContextPropertyUtils.resolvePlaceholders(location, servletContext);

            // Leave a URL (e.g. "classpath:" or "file:") as-is.
            if (!ResourceUtils.isUrl(location)) {
                // Consider a plain file path as relative to the web application root directory.
                // e.g. "/Users/hanyosh/git/gagu/gagu-example/target/gagu-example/WEB-INF/config/log4j.properties"
                location = WebUtils.getRealPath(servletContext, location);
            }

            // Write log message to server log.
            servletContext.log("Initializing log4j from [" + location + "]");

            // Check whether refresh interval was specified.
            String intervalString = servletContext.getInitParameter(REFRESH_INTERVAL_PARAM);
            if (StringUtils.hasText(intervalString)) {
                // Initialize with refresh interval, i.e. with log4j's watchdog thread,
                // checking the file in the background.
                try {
                    long refreshInterval = Long.parseLong(intervalString);
                    Log4jConfigurer.initLogging(location, refreshInterval);
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException(
                            "Invalid 'log4jRefreshInterval' parameter: " + ex.getMessage());
                }
            } else {
                // Initialize without refresh check, i.e. without log4j's watchdog thread.
                Log4jConfigurer.initLogging(location);
            }
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage());
        }
    }
}

From source file:com.aurel.track.GeneralSettings.java

/**
 * Gets the maximal number of items loaded from the database for performance reasons
 * @return/*from w  w w.j  a v  a 2  s . co m*/
 */
public static int getActionLogTimeout() {
    int actionLogTimeout = 10000;
    if (configMap != null) {
        String actionLogTimeoutStr = configMap.getString(GENERAL_CONFIG.ACTION_LOG_TIMEOUT);
        if (actionLogTimeoutStr != null) {
            try {
                actionLogTimeout = Integer.valueOf(actionLogTimeoutStr);
            } catch (NumberFormatException e) {
                LOGGER.warn("Getting " + GENERAL_CONFIG.ACTION_LOG_TIMEOUT + " as int from "
                        + actionLogTimeoutStr + " failed with " + e.getMessage(), e);
            }
        }
    }
    return actionLogTimeout;
}

From source file:com.aurel.track.GeneralSettings.java

/**
 * Gets the maximal number of items loaded from the database for performance reasons
 * @return//  ww w  . j  av a  2s  . c  om
 */
public static int getHistoryAndEmailDelay() {
    int historyAndEmailDelay = 5;
    if (configMap != null) {
        String historyAndEmailDelayStr = configMap.getString(GENERAL_CONFIG.HISTORY_AND_EMAIL_DELAY);
        if (historyAndEmailDelayStr != null) {
            try {
                historyAndEmailDelay = Integer.valueOf(historyAndEmailDelayStr);
            } catch (NumberFormatException e) {
                LOGGER.warn("Getting " + GENERAL_CONFIG.HISTORY_AND_EMAIL_DELAY + " as int from "
                        + historyAndEmailDelayStr + " failed with " + e.getMessage());
            }

        }
    }
    return historyAndEmailDelay;
}