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:com.impetus.client.mongodb.MongoDBClientFactory.java

/**
 * Gets the connection./*from ww  w .  java  2s  .co m*/
 * 
 * @return the connection
 */
private DB getConnection() {

    PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata()
            .getPersistenceUnitMetadata(getPersistenceUnit());

    Properties props = puMetadata.getProperties();
    String contactNode = null;
    String defaultPort = null;
    String keyspace = null;
    String poolSize = null;
    if (externalProperties != null) {
        contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES);
        defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT);
        keyspace = (String) externalProperties.get(PersistenceProperties.KUNDERA_KEYSPACE);
        poolSize = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE);
    }
    if (contactNode == null) {
        contactNode = (String) props.get(PersistenceProperties.KUNDERA_NODES);
    }
    if (defaultPort == null) {
        defaultPort = (String) props.get(PersistenceProperties.KUNDERA_PORT);
    }
    if (keyspace == null) {
        keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE);
    }
    if (poolSize == null) {
        poolSize = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE);
    }

    onValidation(contactNode, defaultPort);

    List<ServerAddress> addrs = new ArrayList<ServerAddress>();

    MongoClient mongo = null;
    try {
        mongo = onSetMongoServerProperties(contactNode, defaultPort, poolSize, addrs);

        logger.info("Connected to mongodb at " + contactNode + " on port " + defaultPort);
    } catch (NumberFormatException e) {
        logger.error("Invalid format for MONGODB port, Unale to connect!" + "; Caused by:" + e.getMessage());
        throw new ClientLoaderException(e);
    } catch (UnknownHostException e) {
        logger.error("Unable to connect to MONGODB at host " + contactNode + "; Caused by:" + e.getMessage());
        throw new ClientLoaderException(e);
    } catch (MongoException e) {
        logger.error("Unable to connect to MONGODB; Caused by:" + e.getMessage());
        throw new ClientLoaderException(e);
    }

    DB mongoDB = mongo.getDB(keyspace);

    try {
        MongoDBUtils.authenticate(props, externalProperties, mongoDB);
    } catch (ClientLoaderException e) {
        logger.error(e.getMessage());
        throw e;
    }
    logger.info("Connected to mongodb at " + contactNode + " on port " + defaultPort);
    return mongoDB;

}

From source file:business.services.ExcerptListService.java

@Transactional
public List<Integer> processExcerptSelection(InputStream input) {
    List<Integer> result = new ArrayList<Integer>();
    log.info("Processing excerpt selection");
    try {//from ww w  .  ja  v a  2 s .  c om
        CSVReader reader = new CSVReader(new InputStreamReader(input), ';', '"');
        String[] nextLine;
        log.debug("Column names.");
        nextLine = reader.readNext();
        if (nextLine == null || nextLine.length == 0 || !nextLine[0].equals("Sequence number")) {
            reader.close();
            throw new ExcerptSelectionUploadError("Invalid header");
        }
        int line = 2;
        while ((nextLine = reader.readNext()) != null) {
            log.debug("Line " + line);
            if (nextLine != null || nextLine.length > 0) {
                try {
                    Integer selected = Integer.valueOf(nextLine[0]);
                    if (result.contains(selected)) {
                        log.warn("Number already selected before: " + selected + " (line " + line + ")");
                    }
                    if (selected == null) {
                        log.warn("Number null (line " + line + ")");
                    } else {
                        result.add(selected);
                    }
                } catch (NumberFormatException e) {
                    log.warn("Invalid number at line " + line);
                }
            }
            line++;
        }
        reader.close();
        log.info("Selected " + result.size() + " entries.");
        return result;
    } catch (IOException e) {
        throw new FileUploadError(e.getMessage());
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.controllers.PulseController.java

@RequestMapping(value = "/acknowledgeAlert", method = RequestMethod.GET)
public void acknowledgeAlert(HttpServletRequest request, HttpServletResponse response) throws IOException {

    int alertId;// w w  w .  j  av  a 2 s.  c o  m
    JSONObject responseJSON = new JSONObject();

    try {
        alertId = Integer.valueOf(request.getParameter("alertId"));
    } catch (NumberFormatException e) {
        // Empty json response
        response.getOutputStream().write(responseJSON.toString().getBytes());
        if (LOGGER.finerEnabled()) {
            LOGGER.finer(e.getMessage());
        }
        return;
    }

    try {
        // get cluster object
        Cluster cluster = Repository.get().getCluster();

        // set alert is acknowledged
        cluster.acknowledgeAlert(alertId);
        responseJSON.put("status", "deleted");
    } catch (JSONException eJSON) {
        LOGGER.logJSONError(eJSON, null);
    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occured : " + e.getMessage());
        }
    }

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

From source file:com.pivotal.gemfire.tools.pulse.internal.controllers.PulseController.java

@RequestMapping(value = "/clearAlerts", method = RequestMethod.GET)
public void clearAlerts(HttpServletRequest request, HttpServletResponse response) throws IOException {

    int alertType;
    JSONObject responseJSON = new JSONObject();
    try {//from  w  w w  .  ja va 2 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());
    } catch (JSONException eJSON) {
        LOGGER.logJSONError(eJSON, null);
    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occured : " + e.getMessage());
        }
    }

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

From source file:com.core.meka.SOMController.java

private double[][] crearArreglo(String[] patrones, TextArea resultArea) throws NumberFormatException {
    int totalPatrones = patrones.length;
    int dimension = patrones[0].split(",").length;
    double[][] result = new double[totalPatrones][dimension];

    for (int i = 0; i < totalPatrones; i++) {
        String[] patron = patrones[i].split(",");
        double[] patronDouble = new double[dimension];
        for (int j = 0; j < patron.length; j++) {
            try {
                patronDouble[j] = Double.valueOf(patron[j]);
            } catch (NumberFormatException e) {
                resultArea.setText("Imposible formatear ese numero, verifiquelo\n"
                        + e.getMessage().replaceAll("\\)", ")\n")
                                .replaceAll("For input string", "Cadena de entrada")
                                .replaceAll("multiple points", "Puntos multiples")
                        + ": " + patron[j] + "\n\n" + resultArea.getText());
                throw new NumberFormatException("Imposible formatear ese numero, veriquelo");
            }//  w  ww  .  j  a  v  a  2 s  . c  o  m
        }
        result[i] = patronDouble;
    }

    return result;
}

From source file:net.jmhertlein.alphonseirc.AlphonseBot.java

private void handleDadCommand(final String target, String sender, String[] args) {
    if (args.length == 1) {
        sendMessage(target, "Usage: !dad [left|list|say]");
        return;//  w w w .  j a  v  a 2  s .c  o  m
    }

    switch (args[1]) {
    case "left":
        ZonedDateTime now = ZonedDateTime.now();
        this.dadLeaveTimes.put(LocalDate.now(), LocalTime.now());
        sendMessage(target,
                "Marked dad's leave time as now (" + now.format(DateTimeFormatter.ISO_LOCAL_TIME) + ").");
        break;
    case "list":
        int num = 3;
        if (args.length == 3) {
            try {
                num = Integer.parseInt(args[2]);
                if (num > 10)
                    num = 10;
            } catch (NumberFormatException nfe) {
                sendMessage(target, "Error parsing " + args[2] + " into int: " + nfe.getMessage());
                sendMessage(target, "Usage: !dad list (optional: number, default 3, max 10)");
                return;
            }
        }

        final int prevDays = num;
        dadLeaveTimes.keySet().stream().sorted()
                .filter(date -> date.isAfter(LocalDate.now().minusDays(prevDays)))
                .map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " || "
                        + dadLeaveTimes.get(date).format(DateTimeFormatter.ISO_LOCAL_TIME))
                .forEach(leaveTime -> sendMessage(target, leaveTime));

        break;
    case "say":
        String msg;
        switch (gen.nextInt(9)) {
        case 0:
            msg = "TYPES LOUDLY";
            break;
        case 1:
            msg = "BREATHES DEEPLY";
            break;
        case 2:
            msg = "ANGRILY TYPES AN EMAIL";
            break;
        case 3:
            msg = "BACKSPACES WITH AUTHORITY";
            break;
        case 4:
            msg = "STRETCHES WHILE EXHALING";
            break;
        case 5:
            msg = "thinks about Happy Hour";
            break;
        case 6:
            msg = "browses Yahoo! news";
            break;
        case 7:
            msg = "tells everyone to GET BACK TO WORK";
            break;
        case 8:
            msg = "ignores Lantzer standing in front of his desk";
            break;
        default:
            msg = "Someone made nextInt() go too high";
            break;
        }

        this.sendAction(target, msg);
        break;
    default:
        System.out.println("Bad switch on " + args[1]);
    }

}

From source file:com.sirma.itt.cmf.integration.workflow.alfresco4.CMFTaskInstancesGet.java

/**
 * Retrieves the named parameter as an integer, if the parameter is not
 * present the default value is returned.
 *
 * @param req//from ww  w . j a v a  2 s.c om
 *            The WebScript request
 * @param paramName
 *            The name of parameter to look for
 * @param defaultValue
 *            The default value that should be returned if parameter is not
 *            present in request or if it is not positive
 * @return The request parameter or default value
 */
protected int getIntParameter(WebScriptRequest req, String paramName, int defaultValue) {
    String paramString = req.getParameter(paramName);

    if (paramString != null) {
        try {
            int param = Integer.valueOf(paramString);

            if (param > 0) {
                return param;
            }
        } catch (NumberFormatException e) {
            throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
        }
    }

    return defaultValue;
}

From source file:data.services.FeatureService.java

public void updateFromXml(File fl) {
    try {//w  w  w  .  j av a2s  . c  om
        FileInputStream fi = new FileInputStream(fl);
        int rownumber = 1;
        HSSFWorkbook workbook = new HSSFWorkbook(fi);
        try {
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> it = sheet.iterator();
            it.next();
            while (it.hasNext()) {
                rownumber++;
                Row row = it.next();
                Cell idc = row.getCell(0);
                Long id = null;
                if (idc != null) {
                    id = StringAdapter.toLong(StringAdapter.HSSFSellValue(row.getCell(0)));
                }
                if (id != null) {

                    Cell uidc = row.getCell(5);
                    String uid = "";
                    if (uidc != null) {
                        uid = StringAdapter.HSSFSellValue(uidc);
                        if (uid.contains(".")) {
                            int point = uid.indexOf(".");
                            uid = uid.substring(0, point);
                        }
                    }

                    Cell valc = row.getCell(6);
                    Double val = (double) 0;
                    if (valc != null) {
                        String valstr = StringAdapter.HSSFSellValue(valc);
                        val = StringAdapter.toDouble(valstr);
                    }

                    Cell percc = row.getCell(7);
                    Long perc = (long) 0;
                    if (percc != null) {
                        String percstr = StringAdapter.HSSFSellValue(percc);
                        if (percstr.contains(".")) {
                            int point = percstr.indexOf(".");
                            percstr = percstr.substring(0, point);
                        }
                        if (!percstr.equals("")) {
                            perc = StringAdapter.toLong(percstr);
                        }
                    }

                    Cell radc = row.getCell(8);
                    String rad = "";
                    if (radc != null) {
                        rad = StringAdapter.HSSFSellValue(radc).trim();
                        if (rad.contains(".")) {
                            int point = rad.indexOf(".");
                            rad = rad.substring(0, point);
                        }
                        if (rad.trim().equals("0")) {
                            rad = "";
                        } else {
                            rad = rad.replace(" ", "");
                        }
                    }

                    Cell ac = row.getCell(9);
                    String a = "0";
                    if (ac != null) {
                        a = StringAdapter.HSSFSellValue(ac);
                        if (a.contains(".")) {
                            int point = a.indexOf(".");
                            a = a.substring(0, point);
                        }
                        if (a.equals("")) {
                            a = "0";
                        }
                    }
                    Cell vc = row.getCell(10);
                    String v = "0";
                    if (vc != null) {
                        v = StringAdapter.HSSFSellValue(vc);
                        if (v.contains(".")) {
                            int point = v.indexOf(".");
                            v = v.substring(0, point);
                        }
                        if (v.equals("")) {
                            v = "0";
                        }
                    }
                    Cell kc = row.getCell(11);
                    String k = "0";
                    if (kc != null) {
                        k = StringAdapter.HSSFSellValue(kc);
                        if (k.contains(".")) {
                            int point = k.indexOf(".");
                            k = k.substring(0, point);
                        }
                        if (k.equals("")) {
                            k = "0";
                        }
                    }
                    Feature cl = featureDao.find(id);
                    if (cl != null) {
                        cl.setUid(uid);
                        cl.setParamValue(val);
                        cl.setPercentValue(perc);
                        cl.setRadical(rad);
                        cl.setAudial(Integer.valueOf(a));
                        cl.setVisual(Integer.valueOf(v));
                        cl.setKinestet(Integer.valueOf(k));
                        if (validate(cl, " " + rownumber + ";   ")) {
                            featureDao.update(cl);
                        }
                    }
                }
            }
        } catch (NumberFormatException e) {
            addError(" " + rownumber + ";   "
                    + StringAdapter.getStackTraceException(e));
        }
        workbook.close();
        fi.close();
    } catch (IOException e) {
        addError("  xml");
        addError(e.getMessage());
    }
}

From source file:com.gdevelop.gwt.syncrpc.SyncClientSerializationStreamReader.java

public int readInt() {
    Log.d("PROBLEMA", "Before parsing readInt: " + index);
    try {// w w w . j  a v  a  2 s.co m
        return Integer.parseInt(results.get(--index));
    } catch (NumberFormatException nfe) {
        LOG.error("Serialiazation error " + nfe.getMessage() + " - " + origEncoded);
        throw nfe;
    }
}

From source file:org.apache.manifoldcf.agents.output.amazoncloudsearch.AmazonCloudSearchConnector.java

/** Set up a session */
protected void getSession() throws ManifoldCFException {
    if (documentChunkManager == null) {
        IDBInterface databaseHandle = DBInterfaceFactory.make(currentContext,
                ManifoldCF.getMasterDatabaseName(), ManifoldCF.getMasterDatabaseUsername(),
                ManifoldCF.getMasterDatabasePassword());
        documentChunkManager = new DocumentChunkManager(databaseHandle);
    }/*from  w  w  w  . ja  va 2s .  c o m*/

    serverHost = params.getParameter(AmazonCloudSearchConfig.SERVER_HOST);
    if (serverHost == null)
        throw new ManifoldCFException("Server host parameter required");
    serverPath = params.getParameter(AmazonCloudSearchConfig.SERVER_PATH);
    if (serverPath == null)
        throw new ManifoldCFException("Server path parameter required");
    String proxyProtocol = params.getParameter(AmazonCloudSearchConfig.PROXY_PROTOCOL);
    String proxyHost = params.getParameter(AmazonCloudSearchConfig.PROXY_HOST);
    String proxyPort = params.getParameter(AmazonCloudSearchConfig.PROXY_PORT);

    // Https is OK here without a custom trust store because we know we are talking to an Amazon instance, which has certs that
    // are presumably non-custom.
    String urlStr = "https://" + serverHost + serverPath;
    poster = new HttpPost(urlStr);

    //set proxy
    if (proxyHost != null && proxyHost.length() > 0) {
        try {
            HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort), proxyProtocol);
            RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
            poster.setConfig(config);
        } catch (NumberFormatException e) {
            throw new ManifoldCFException("Number format exception: " + e.getMessage(), e);
        }
    }

    poster.addHeader("Content-Type", "application/json");
}