Example usage for java.lang NumberFormatException fillInStackTrace

List of usage examples for java.lang NumberFormatException fillInStackTrace

Introduction

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

Prototype

public synchronized Throwable fillInStackTrace() 

Source Link

Document

Fills in the execution stack trace.

Usage

From source file:com.highcharts.export.controller.ExportController.java

private static Float scaleToFloat(String scale) throws SVGConverterException {
    scale = sanitize(scale);/*from ww  w .  ja  v  a2  s. c o m*/
    if (scale != null) {
        try {
            Float parsedScale = Float.valueOf(scale);
            if (parsedScale.compareTo(MAX_SCALE) > 0) {
                return MAX_SCALE;
            } else if (parsedScale.compareTo(0.0F) > 0) {
                return parsedScale;
            }
        } catch (NumberFormatException nfe) {
            logger.error("Parameter scale is wrong for value: " + scale, nfe.fillInStackTrace());
            throw new SVGConverterException("Parameter scale is wrong for value: " + scale);
        }
    }
    return null;
}

From source file:com.highcharts.export.controller.ExportController.java

private static Float widthToFloat(String width) throws SVGConverterException {
    width = sanitize(width);/*w  w w . j av  a  2s .com*/
    if (width != null) {
        width = width.replace("px", "");
        try {
            Float parsedWidth = Float.valueOf(width);
            if (parsedWidth.compareTo(MAX_WIDTH) > 0) {
                return MAX_WIDTH;
            }
            if (parsedWidth.compareTo(0.0F) > 0) {
                return parsedWidth;
            }
        } catch (NumberFormatException nfe) {
            logger.error("Parameter width is wrong for value: " + width, nfe.fillInStackTrace());
            throw new SVGConverterException("Parameter width is wrong for value: " + width);
        }

    }
    return null;
}

From source file:com.mycompany.parcinghtml.ParsingClassPlayers.java

public void downloadSource() throws SQLException {
    //ds = prepareDataSource();
    String sql = "INSERT INTO PLAYERS(NAME,AGE,HEIGHT,WEIGHT,PLAYERNUM,POSITION,PLAYERID) VALUES(?,?,?,?,?,?,?)";
    ArrayList<String> duplicity = new ArrayList<>();
    int playerID = 1;

    for (int i = 2015; i > 2004; i--) {
        Document doc = null;//w  w  w  .  j ava 2s .co  m
        try {
            doc = Jsoup.connect("http://www.hcsparta.cz/soupiska.asp?sezona=" + Integer.toString(i)).get();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        if (doc == null) {
            System.out.println("doc is null");
            return;
        }

        Elements posNum;
        Elements elList;
        posNum = doc.getElementsByAttributeValueContaining("class", "soupiska");
        //elList = doc.getElementsByAttributeValueContaining("id", "soupiska");
        for (int j = 0; j < 3; j++) {
            elList = posNum.get(j).getElementsByAttributeValueContaining("id", "soupiska");

            for (Element item : elList) {
                String[] secondName = item.child(2).text().split(" ");
                if (duplicity.contains(item.child(2).text()))
                    continue;
                duplicity.add(item.child(2).text());
                try (Connection conn = ds.getConnection()) {

                    try (PreparedStatement st = conn.prepareStatement(sql)) {
                        st.setString(1, item.child(2).text());
                        String[] age = item.child(4).text().split(" ");
                        st.setInt(2, Integer.parseInt(age[0]));
                        String[] height = item.child(5).text().split(" ");
                        st.setInt(3, Integer.parseInt(height[0]));
                        String[] weight = item.child(6).text().split(" ");
                        st.setInt(4, Integer.parseInt(weight[0]));

                        try {
                            st.setInt(5, Integer.parseInt(item.child(0).text()));
                        } catch (NumberFormatException ex) {
                            st.setInt(5, 0);
                        }
                        st.setInt(6, j);
                        st.setInt(7, playerID);
                        int addedRows = st.executeUpdate();
                        playerID++;
                    }
                } catch (SQLException ex) {
                    throw new SQLException(ex.getMessage(), ex.fillInStackTrace());
                }

            }
        }

    }

}

From source file:org.bml.util.sql.DBUtil.java

/**
 *
 * @param ps/*w  w w  .j a v  a  2 s.c  om*/
 * @param keyName
 * @param fieldId
 * @param map
 * @param remove
 * @param dateFormat
 * @throws SQLException
 * @throws ParseException
 */
public static void setTimeStamp(PreparedStatement ps, String keyName, int fieldId, Map<String, String> map,
        boolean remove, DateFormat dateFormat) throws SQLException, ParseException, NumberFormatException {
    String val = map.get(keyName);
    if (remove) {
        map.remove(keyName);
    }
    if (val == null) {
        ps.setTimestamp(fieldId, null);
        return;
    }
    Date parse, currentDate = new Date(new Date().getTime() + 3600000);
    try {
        parse = dateFormat.parse(val);
        if (parse.after(currentDate)) {
            LOG.warn("Date parsed from FIELD=" + keyName + " VALUE=" + val
                    + " Is more than one hour in the future.");
        }
        if (parse.before(TimeUtils.UTC_DATE_2005)) {
            LOG.warn("Date parsed from FIELD=" + keyName + " VALUE=" + val + " Is before .");
        }

    } catch (NumberFormatException nfe) {
        nfe.fillInStackTrace();
        throw nfe;
    }
    Timestamp timestamp = new Timestamp(parse.getTime());
    ps.setTimestamp(fieldId, timestamp);
}

From source file:org.opennms.netmgt.poller.monitors.SmtpMonitor.java

/**
 * {@inheritDoc}/*from  ww w  .  j a v  a 2  s  . com*/
 *
 * <P>
 * Poll the specified address for SMTP service availability.
 * </P>
 *
 * <P>
 * During the poll an attempt is made to connect on the specified port (by
 * default TCP port 25). If the connection request is successful, the banner
 * line generated by the interface is parsed and if the extracted return
 * code indicates that we are talking to an SMTP server we continue. Next,
 * an SMTP 'HELO' command is sent to the interface. Again the response is
 * parsed and a return code extracted and verified. Finally, an SMTP 'QUIT'
 * command is sent. Provided that the interface's response is valid we set
 * the service status to SERVICE_AVAILABLE and return.
 * </P>
 */
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
    NetworkInterface<InetAddress> iface = svc.getNetInterface();

    // Get interface address from NetworkInterface
    //
    if (iface.getType() != NetworkInterface.TYPE_INET) {
        throw new NetworkInterfaceNotSupportedException(
                "Unsupported interface type, only TYPE_INET currently supported");
    }

    TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT);

    int port = ParameterMap.getKeyedInteger(parameters, "port", DEFAULT_PORT);

    // Get interface address from NetworkInterface
    //
    InetAddress ipAddr = iface.getAddress();

    final String hostAddress = InetAddressUtils.str(ipAddr);
    LOG.debug("poll: address = {}, port = {}, {}", hostAddress, port, tracker);

    PollStatus serviceStatus = PollStatus.unavailable();

    for (tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt()) {
        Socket socket = null;
        try {
            // create a connected socket
            //
            tracker.startAttempt();

            socket = new Socket();
            socket.connect(new InetSocketAddress(ipAddr, port), tracker.getConnectionTimeout());
            socket.setSoTimeout(tracker.getSoTimeout());

            LOG.debug("SmtpMonitor: connected to host: {} on port: {}", ipAddr, port);

            // We're connected, so upgrade status to unresponsive
            serviceStatus = PollStatus.unresponsive();
            // Forcing to check for CRLF instead of any other line terminator as per RFC specification
            CRLFLineReader rdr = new CRLFLineReader(new InputStreamReader(socket.getInputStream(), "ASCII"));

            //
            // Tokenize the Banner Line, and check the first
            // line for a valid return.
            //
            String banner = sendMessage(socket, rdr, null);
            LOG.debug("poll: banner = {}", banner);

            StringTokenizer t = new StringTokenizer(banner);
            int rc = Integer.parseInt(t.nextToken());
            if (rc == 220) {
                //
                // Send the HELO command
                //
                String cmd = "HELO " + LOCALHOST_NAME + "\r\n";
                socket.getOutputStream().write(cmd.getBytes());

                //
                // get the returned string, tokenize, and
                // verify the correct output.
                //
                String response = rdr.readLine();
                double responseTime = tracker.elapsedTimeInMillis();

                if (response == null) {
                    continue;
                }

                if (MULTILINE.matcher(response).find()) {
                    // Ok we have a multi-line response...first three
                    // chars of the response line are the return code.
                    // The last line of the response will start with
                    // return code followed by a space.
                    String multiLineRC = new String(response.getBytes("ASCII"), 0, 3, "ASCII");

                    // Create new regExp to look for last line
                    // of this multi line response
                    Pattern endMultiline = null;
                    try {
                        endMultiline = Pattern.compile(multiLineRC);
                    } catch (PatternSyntaxException ex) {
                        throw new java.lang.reflect.UndeclaredThrowableException(ex);
                    }

                    // read until we hit the last line of the multi-line
                    // response
                    do {
                        response = rdr.readLine();
                    } while (response != null && !endMultiline.matcher(response).find());
                    if (response == null) {
                        continue;
                    }
                }

                t = new StringTokenizer(response);
                rc = Integer.parseInt(t.nextToken());
                if (rc == 250) {
                    response = sendMessage(socket, rdr, "QUIT\r\n");

                    t = new StringTokenizer(response);
                    rc = Integer.parseInt(t.nextToken());

                    if (rc == 221) {
                        serviceStatus = PollStatus.available(responseTime);
                    }
                }
            } else if (rc == 554) {
                String response = sendMessage(socket, rdr, "QUIT\r\n");
                serviceStatus = PollStatus.unavailable("Server rejecting transactions with 554");
            }

            // If we get this far and the status has not been set to
            // available, then something didn't verify during the banner
            // checking or HELO/QUIT comand process.
            if (!serviceStatus.isAvailable()) {
                serviceStatus = PollStatus.unavailable(serviceStatus.getReason());
            }
        } catch (NumberFormatException e) {
            String reason = "NumberFormatException while polling address " + hostAddress;
            LOG.debug(reason, e);
            serviceStatus = PollStatus.unavailable(reason);
        } catch (NoRouteToHostException e) {
            String reason = "No route to host exception for address " + hostAddress;
            LOG.debug(reason, e);
            serviceStatus = PollStatus.unavailable(reason);
            break; // Break out of for(;;)
        } catch (InterruptedIOException e) {
            String reason = "Did not receive expected response within timeout " + tracker;
            LOG.debug(reason);
            serviceStatus = PollStatus.unavailable(reason);
        } catch (ConnectException e) {
            String reason = "Unable to connect to address " + hostAddress;
            LOG.debug(reason, e);
            serviceStatus = PollStatus.unavailable(reason);
        } catch (IOException e) {
            String reason = "IOException while polling address " + hostAddress;
            LOG.debug(reason, e);
            serviceStatus = PollStatus.unavailable(reason);
        } finally {
            try {
                // Close the socket
                if (socket != null) {
                    socket.close();
                }
            } catch (IOException e) {
                e.fillInStackTrace();
                LOG.debug("poll: Error closing socket.", e);
            }
        }
    }

    //
    // return the status of the service
    //
    return serviceStatus;
}

From source file:uk.nhs.cfh.dsp.snomed.mrcm.impl.MRCMGeneratorImpl.java

public synchronized void generateMRCMTable(File file) {

    try {//w  w  w. j  a v a2s.c om
        Scanner scanner = new Scanner(file);
        // delete all entries in exising mrcm repo
        mrcmDao.deleteAllConstraints();
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine().trim();
            // remove all cg operators in line
            line = line.replaceAll("<<", "");
            line = line.replaceAll("=", "");
            String[] parts = line.split("\\t");
            if (parts.length == 6) {
                MRCMConstraint constraint = new MRCMConstraintImpl();
                constraint.setSourceId(parts[0]);
                constraint.setSourceName(parts[3]);
                constraint.setAttributeId(parts[1]);
                constraint.setValueId(parts[2]);
                constraint.setValueName(parts[5]);

                // process attribute name column to extract cardinality values
                String attributeName = parts[4];
                int minCardinality = 0;
                int maxCardinality = -1;
                int colonIndex = attributeName.indexOf(':');
                if (colonIndex > 0) {
                    String minString = attributeName.substring(colonIndex - 1, colonIndex);
                    String maxString = attributeName.substring(colonIndex + 1, colonIndex + 2);
                    // replace * in maxString with -1 if present, to indicate unbounded cardinality
                    if (maxString.indexOf('*') > -1) {
                        maxString = "-1";
                    }

                    try {
                        minCardinality = Integer.parseInt(minString);
                        maxCardinality = Integer.parseInt(maxString);
                    } catch (NumberFormatException e) {
                        logger.warn("Error generating cardinality from line.\n" + "Nested exception is : "
                                + e.fillInStackTrace());
                    }
                }

                constraint.setMinCardinality(minCardinality);
                constraint.setMaxCardinality(maxCardinality);
                // now strip out All cardinality and related info from attributeName
                attributeName = attributeName.substring(colonIndex + 8).trim();
                constraint.setAttributeName(attributeName);
                mrcmDao.saveConstraint(constraint);
            }
        }
    } catch (FileNotFoundException e) {
        logger.warn("Error reading from file. Check file exists and is readable.\n" + " Nested exception is : "
                + e.fillInStackTrace());
    }

}

From source file:uk.nhs.cfh.dsp.srth.demographics.impl.PatientDAOImpl.java

public Patient findPatient(String patientId) {
    try {/*from   www .  ja va 2s.  c  o  m*/
        Long id = Long.parseLong(patientId);
        return findPatient(id);
    } catch (NumberFormatException e) {
        logger.warn("Nested exception is : " + e.fillInStackTrace().getMessage());
        return null;
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.queryresultspanel.model.table.ResultSetTableModel.java

/**
 * converts the table column name from the database style with underscores
 * to a more human readable form./* www.  j a  va2  s.  c  om*/
 * 
 * @param dbColName the db col name
 * 
 * @return the string
 */
private String convertDBColumnNameToJTableColumnName(String dbColName) {

    String jTableColumnName = "";
    /*
     * we know the columns name style in the db looks like ENTRY_TIME_TABLE_NAME_SUB_QUERY_NUMBER
     * So to convert this, we replace all underscores and create a human readable version as
     * Entry Time # where # is the sub query id.
     */
    // get sub query number
    String subQueryId = dbColName.substring(dbColName.lastIndexOf("_") + 1);

    int subQueryNumber = 0;
    try {
        if (!"ID".equalsIgnoreCase(subQueryId)) {
            subQueryNumber = Integer.parseInt(subQueryId);
        }
    } catch (NumberFormatException e) {
        logger.warn(e.fillInStackTrace());
    }
    //increment since sub query ids start from 0 and not 1
    subQueryNumber = subQueryNumber + 1;

    if (dbColName.indexOf("Concept") > -1) {
        jTableColumnName = "Concept ID " + subQueryNumber;
    } else if (dbColName.indexOf("Entry_Time") > -1) {
        jTableColumnName = "Entry Time " + subQueryNumber;
    } else if (dbColName.indexOf("Free_Text_Entry") > -1) {
        jTableColumnName = "Term Text " + subQueryNumber;
    } else {
        jTableColumnName = dbColName.replaceAll("_", " ");
    }

    return jTableColumnName;
}