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:org.hyperic.hq.plugin.netservices.HTTPCollector.java

protected void parseResults(HttpResponse response) {
    Header length = response.getFirstHeader("Content-Length");
    Header type = response.getFirstHeader("Content-Type");

    if (type == null || !type.getValue().equals("text/plain")) {
        return;//w ww . j a  v  a2 s .co  m
    }

    if (length != null) {
        try {
            if (Integer.parseInt(length.getValue()) > 8192) {
                return;
            }
        } catch (NumberFormatException e) {
            return;
        }
    }

    try {
        parseResults(EntityUtils.toString(response.getEntity(), "UTF-8"));
    } catch (ParseException e) {
        setErrorMessage("Exception parsing response: " + e.getMessage(), e);
    } catch (IOException e) {
        setErrorMessage("Exception reading response stream: " + e.getMessage(), e);
    }
}

From source file:net.di2e.ecdr.commons.query.rest.parsers.BasicQueryParser.java

protected GeospatialCriteria createGeospatialCriteria(String rad, String lat, String lon, String box,
        String geom, String polygon, boolean strictMode) throws UnsupportedQueryException {
    GeospatialCriteria geoCriteria = null;
    if (StringUtils.isNotBlank(box)) {
        try {/*from   w w  w  .ja v a  2s  . co  m*/
            String[] bboxArray = box.split(" |,\\p{Space}?");

            if (bboxArray.length != 3) {
                double minX = Double.parseDouble(bboxArray[0]);
                double minY = Double.parseDouble(bboxArray[1]);
                double maxX = Double.parseDouble(bboxArray[2]);
                double maxY = Double.parseDouble(bboxArray[3]);
                geoCriteria = new GeospatialCriteria(minX, minY, maxX, maxY);
            } else {
                throw new UnsupportedQueryException("Invalid values found for bbox [" + box + "]");
            }

        } catch (NumberFormatException e) {
            LOGGER.warn("Invalid values found for bbox [{}].  Resulted in exception: {}", box, e.getMessage());
            if (strictMode) {
                throw new UnsupportedQueryException(
                        "Invalid values found for bbox [" + box + "], values must be numeric.");
            }
        }
        // Only check lat and lon. If Radius is blank is should be defaulted
    } else if (StringUtils.isNotBlank(lat) && StringUtils.isNotBlank(lon)) {
        try {
            double longitude = Double.parseDouble(lon);
            double latitude = Double.parseDouble(lat);
            double radius = StringUtils.isNotBlank(rad) ? Double.parseDouble(rad) : this.defaultRadius;
            geoCriteria = new GeospatialCriteria(latitude, longitude, radius);

        } catch (NumberFormatException e) {
            LOGGER.warn(
                    "Invalid Number found for lat [{}], lon [{}], and/or radius [{}].  Resulted in exception: {}",
                    lat, lon, rad, e.getMessage());
            if (strictMode) {
                throw new UnsupportedQueryException("Invalid Number found for lat [" + lat + "], lon [" + lon
                        + "], and/or radius [" + rad + "].");
            }
        }

    } else if (StringUtils.isNotBlank(geom)) {
        try {
            WKTReader reader = new WKTReader();
            reader.read(geom);
        } catch (ParseException e) {
            LOGGER.warn("The following is not a valid WKT String: {}", geom);
            throw new UnsupportedQueryException("Invalid WKT, cannot create geospatial query.");
        }
        geoCriteria = new GeospatialCriteria(geom);
    } else if (StringUtils.isNotBlank(polygon)) {
        String wkt = GeospatialHelper.polygonToWKT(polygon);
        try {
            WKTReader reader = new WKTReader();
            reader.read(wkt);
        } catch (ParseException e) {
            LOGGER.warn("The following is not a valid WKT String: {}", wkt);
            throw new UnsupportedQueryException("Invalid WKT, cannot create geospatial query.");
        }
        geoCriteria = new GeospatialCriteria(wkt);
    }
    return geoCriteria;
}

From source file:net.duckling.ddl.web.controller.LynxDDocController.java

private int getRequestVersion(HttpServletRequest request) {
    String version = request.getParameter("version");
    if (version != null) {
        try {// w w w  .  ja v a  2  s  . com
            return Integer.parseInt(version);
        } catch (NumberFormatException e) {
            LOG.warn(e.getMessage(), e);
        }
    }
    return VWBContext.LATEST_VERSION;
}

From source file:javazoom.jlgui.player.amp.visual.ui.SpectrumTimeAnalyzer.java

/**
 * Convert string to color./*from w w w .j av  a  2s .co m*/
 * @param linecolor
 * @return
 */
public Color getColor(String linecolor) {
    Color color = Color.BLACK;
    StringTokenizer st = new StringTokenizer(linecolor, ",");
    int red = 0, green = 0, blue = 0;
    try {
        if (st.hasMoreTokens())
            red = Integer.parseInt(st.nextToken().trim());
        if (st.hasMoreTokens())
            green = Integer.parseInt(st.nextToken().trim());
        if (st.hasMoreTokens()) {
            String blueStr = st.nextToken().trim();
            if (blueStr.length() > 3)
                blueStr = (blueStr.substring(0, 3)).trim();
            blue = Integer.parseInt(blueStr);
        }
        color = new Color(red, green, blue);
    } catch (NumberFormatException e) {
        log.debug("Cannot parse viscolor : " + e.getMessage());
    }
    return color;
}

From source file:net.di2e.ecdr.commons.query.rest.parsers.BasicQueryParser.java

@Override
public int getStartIndex(MultivaluedMap<String, String> queryParameters) throws UnsupportedQueryException {
    String startIndex = queryParameters.getFirst(SearchConstants.STARTINDEX_PARAMETER);
    int index = 1;
    LOGGER.debug("Attempting to set 'startIndex' value from request [{}] to int", startIndex);
    if (StringUtils.isNotBlank(startIndex)) {
        try {/*  w  w w.  j  av  a 2s. c  om*/
            index = Integer.parseInt(startIndex);
        } catch (NumberFormatException e) {
            String message = "Invalid Number found for 'startIndex' [" + startIndex
                    + "].  Resulted in exception: " + e.getMessage();
            LOGGER.warn(message);
            throw new UnsupportedQueryException(message);
        }
    } else {
        LOGGER.debug("'startIndex' parameter was not specified, defaulting value to [{}]", index);
    }
    return index < 1 ? 1 : index;
}

From source file:net.di2e.ecdr.commons.query.rest.parsers.BasicQueryParser.java

@Override
public long getTimeoutMilliseconds(MultivaluedMap<String, String> queryParameters)
        throws UnsupportedQueryException {
    String timeout = queryParameters.getFirst(SearchConstants.TIMEOUT_PARAMETER);
    long timeoutMilliseconds = this.defaultTimeoutMillis;
    LOGGER.debug("Attempting to set 'timeout' value from request [" + timeout + "] to long");
    if (StringUtils.isNotBlank(timeout)) {
        try {//from  www  .  ja  va2s  . c  om
            timeoutMilliseconds = Long.parseLong(timeout);
            if (timeoutMilliseconds <= 0) {
                throw new UnsupportedQueryException("The [" + SearchConstants.TIMEOUT_PARAMETER
                        + "] parameter cannot nbe less than 0 and was [" + timeout + "]");
            }
        } catch (NumberFormatException e) {
            String message = "Invalid Number found for 'timeout' [" + timeout + "].  Resulted in exception: "
                    + e.getMessage();
            LOGGER.warn(message);
            if (isStrictMode(queryParameters)) {
                throw new UnsupportedQueryException(message);
            }
        }
    } else {
        LOGGER.debug("'timeout' parameter was not specified, defaulting value to [{}]", timeout);
    }
    return timeoutMilliseconds;
}

From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java

@RequestMapping(value = "/clearAlerts", method = RequestMethod.GET)
public void clearAlerts(HttpServletRequest request, HttpServletResponse response) throws IOException {
    int alertType;
    ObjectNode responseJSON = mapper.createObjectNode();

    try {//from  w  ww  .  j a  v  a2 s  .  c om
        alertType = Integer.valueOf(request.getParameter("alertType"));
    } catch (NumberFormatException e) {
        // Empty json response
        response.getOutputStream().write(responseJSON.toString().getBytes());
        if (LOGGER.finerEnabled()) {
            LOGGER.finer(e.getMessage());
        }
        return;
    }

    try {
        boolean isClearAll = Boolean.valueOf(request.getParameter("clearAll"));
        // get cluster object
        Cluster cluster = Repository.get().getCluster();
        cluster.clearAlerts(alertType, isClearAll);
        responseJSON.put("status", "deleted");
        responseJSON.put("systemAlerts",
                SystemAlertsService.getAlertsJson(cluster, cluster.getNotificationPageNumber()));
        responseJSON.put("pageNumber", cluster.getNotificationPageNumber());

        boolean isGFConnected = cluster.isConnectedFlag();
        if (isGFConnected) {
            responseJSON.put("connectedFlag", isGFConnected);
        } else {
            responseJSON.put("connectedFlag", isGFConnected);
            responseJSON.put("connectedErrorMsg", cluster.getConnectionErrorMsg());
        }
    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occurred : " + e.getMessage());
        }
    }

    // Send json response
    response.getOutputStream().write(responseJSON.toString().getBytes());
}

From source file:iddb.core.IDDBService.java

public Server getServer(String key) throws EntityDoesNotExistsException, ApplicationError {
    try {/*from   w ww.  j  a va2s.  com*/
        return getServer(Long.parseLong(key));
    } catch (NumberFormatException e) {
        log.error("NumberFormatException: [value {}] {}", key, e.getMessage());
        return null;
    }
}

From source file:com.controlj.addon.weather.servlets.AjaxController.java

private void showData(ConfigData configData, ResponseWriter writer, HttpServletRequest req) throws IOException {
    String rowString = req.getParameter(ROW_PARAM_NAME);
    try {/*  w w w . j  a  v  a  2s.c om*/
        int rowNum = Integer.parseInt(rowString);
        WeatherConfigEntry entry = configData.getList().get(rowNum);

        // display name
        WeatherServiceUI ui = configData.getWeatherService().getUI();
        String displayName = ui.getEntryDisplayName(entry);
        writer.putString(JSON_NAME, displayName);

        // station data
        StationSource stationSource = entry.getStationSource();
        if (stationSource != null) {
            for (StationField field : StationField.values()) {
                if (field.isSupported(stationSource, configData)) {
                    Map<String, Object> row = new HashMap<String, Object>(2);
                    row.put(JSON_FIELD, field.getName());
                    row.put(JSON_VALUE, formatValue(field.getValue(stationSource, configData)));
                    writer.appendToArray(JSON_STATION, row);
                }
            }
        }

        WeatherLookup weatherLookup = new WeatherLookup(configData);

        // current conditions
        ConditionsSource conditionsSource = weatherLookup.lookupConditionsData(entry, true);
        if (conditionsSource != null) {
            for (ConditionsField field : ConditionsField.values()) {
                if (field.isSupported(conditionsSource)) {
                    Map<String, Object> row = new HashMap<String, Object>(3);
                    row.put(JSON_FIELD, field.getName());
                    row.put(JSON_VALUE, formatValue(field.getValue(conditionsSource)));
                    row.put(JSON_UNITS, formatValue(field.getUnits(conditionsSource)));
                    writer.appendToArray(JSON_CURRENT, row);
                }
            }
        }

        // forecast data
        ForecastSource[] forecastSources = weatherLookup.lookupForecastsData(entry, true);
        if (forecastSources != null) {
            writer.appendToArray(JSON_FORECAST_HEADERS, "Field");
            for (int i = 0; i < forecastSources.length; i++) {
                writer.appendToArray(JSON_FORECAST_HEADERS, "Day " + i + " Value");
            }

            for (ForecastField field : ForecastField.values()) {
                if (field.isSupported(forecastSources[0])) {
                    Map<String, Object> row[] = new Map[forecastSources.length + 1];
                    row[0] = new HashMap<String, Object>();
                    row[0].put(JSON_VALUE, field.getName('?'));
                    row[0].put(JSON_UNITS, "");
                    int i = 1;
                    for (ForecastSource forecastSource : forecastSources) {
                        row[i] = new HashMap<String, Object>();
                        row[i].put(JSON_VALUE, formatValue(field.getValue(forecastSource)));
                        row[i].put(JSON_UNITS, formatValue(field.getUnits(forecastSource)));
                        ++i;
                    }
                    writer.appendToArray(JSON_FORECAST, row);
                }
            }
        }

        // icon data
        for (WeatherIcon icon : WeatherIcon.values()) {
            Map<String, Object> row = new HashMap<String, Object>(2);
            row.put(JSON_FIELD, icon.getDisplayName());
            row.put(JSON_VALUE, icon.getValue());
            writer.appendToArray(JSON_ICON, row);
        }
    } catch (NumberFormatException e) {
        writer.addError("Error deleting row.  Invalid row number '" + rowString + "'");
        Logging.println("Error deleting row.  Invalid row number '" + rowString + "'", e);
    } catch (WeatherServiceException e) {
        writer.addError("Error getting weather: " + e.getMessage());
        Logging.println("Error getting weather: " + e.getMessage(), e);
    }
}

From source file:com.skelril.aurora.jail.CSVInmateDatabase.java

public synchronized boolean load() {

    FileInputStream input = null;
    boolean successful = true;
    boolean needsSaved = false;

    try {//from  w  ww. j  a v  a 2s  . co m
        input = new FileInputStream(inmateFile);
        InputStreamReader streamReader = new InputStreamReader(input, "utf-8");
        CSVReader reader = new CSVReader(new BufferedReader(streamReader));
        String[] line;

        while ((line = reader.readNext()) != null) {
            if (line.length < 5) {
                log.warning("A jail entry with < 5 fields was found!");
                continue;
            }
            try {
                String rawID = "null";
                String prisonName = "lava-flow";
                String reason = "";
                long startDate = 0;
                long endDate = 0;
                boolean isMuted = false;

                for (int i = 0; i < line.length; i++) {
                    switch (i) {
                    case 0:
                        rawID = line[i].trim().toLowerCase();
                        break;
                    case 1:
                        prisonName = line[i].trim().toLowerCase();
                        break;
                    case 2:
                        reason = line[i].trim().toLowerCase();
                        break;
                    case 3:
                        startDate = Long.parseLong(line[i]);
                        break;
                    case 4:
                        endDate = Long.parseLong(line[i]);
                        break;
                    case 5:
                        isMuted = Boolean.parseBoolean(line[i]);
                        break;
                    }
                }
                if ("".equals(rawID) || "null".equals(rawID))
                    rawID = null;
                Inmate inmate = new Inmate(prisonName, reason, startDate, endDate, isMuted);
                try {
                    inmate.setID(UUID.fromString(rawID));
                } catch (IllegalArgumentException ex) {
                    logger().finest("Converting inmate " + rawID + "'s name to UUID...");
                    UUID creatorID = UUIDUtil.convert(rawID);
                    if (creatorID != null) {
                        inmate.setID(creatorID);
                        needsSaved = true;
                        logger().finest("Success!");
                    } else {
                        inmate.setName(rawID);
                        logger().warning("Inmate " + rawID + "'s name could not be converted!");
                    }
                }
                UUIDInmate.put(inmate.getID(), inmate);
            } catch (NumberFormatException e) {
                log.warning("Non-long long field found in inmate!");
            }
        }
        log.info(UUIDInmate.size() + " jailed name(s) loaded.");
    } catch (FileNotFoundException ignored) {
    } catch (IOException e) {
        UUIDInmate = new HashMap<>();
        log.warning("Failed to load " + inmateFile.getAbsolutePath() + ": " + e.getMessage());
        successful = false;
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ignored) {
            }
        }
    }
    if (needsSaved)
        save();
    return successful;
}