List of usage examples for java.lang NumberFormatException getMessage
public String getMessage()
From source file:com.hybris.datahub.service.impl.handler.DefaultTmallTradesHandler.java
private String extractDiscount(final Map<String, String> orderEntry) { double discount = 0.0; try {// www . jav a 2 s.com discount = Double.parseDouble(orderEntry.get("adjustFee")) + Double.parseDouble(orderEntry.get("discountFee")); } catch (final NumberFormatException e) { LOG.error(e.getMessage(), e); } return String.valueOf(discount); }
From source file:com.digitalpebble.behemoth.io.warc.HttpResponse.java
private int parseStatusLine(PushbackInputStream in, StringBuilder line) throws IOException { // skip first character if "\n" if (peek(in) == '\n') { in.read();//from www .jav a2 s .c o m } readLine(in, line, false); int codeStart = line.indexOf(" "); int codeEnd = line.indexOf(" ", codeStart + 1); // handle lines with no plaintext result code, ie: // "HTTP/1.1 200" vs "HTTP/1.1 200 OK" if (codeEnd == -1) codeEnd = line.length(); int code; try { code = Integer.parseInt(line.substring(codeStart + 1, codeEnd)); } catch (NumberFormatException e) { throw new IOException("bad status line '" + line + "': " + e.getMessage(), e); } return code; }
From source file:example.SimpleChaincode.java
@Override public Response init(ChaincodeStub stub) { try {/*from w w w. java 2 s. c o m*/ final List<String> args = stub.getStringArgs(); switch (args.get(0)) { case "init": return init(stub, args.stream().skip(0).toArray(String[]::new)); default: return newBadRequestResponse(format("Unknown function: %s", args.get(0))); } } catch (NumberFormatException e) { return newBadRequestResponse(e.toString()); } catch (IllegalArgumentException e) { return newBadRequestResponse(e.getMessage()); } catch (Throwable e) { return newInternalServerErrorResponse(e); } }
From source file:com.impetus.kundera.client.MongoDBClient.java
@Override public void connect() { if (!isConnected) { log.info(">>> Connecting to MONGODB at " + contactNode + " on port " + defaultPort); try {/*from w w w .j ava 2 s . c om*/ mongo = new Mongo(contactNode, Integer.parseInt(defaultPort)); mongoDb = mongo.getDB(dbName); isConnected = true; log.info("CONNECTED to MONGODB at " + contactNode + " on port " + defaultPort); } catch (NumberFormatException e) { log.error("Invalid format for MONGODB port, Unale to connect!" + "; Details:" + e.getMessage()); } catch (UnknownHostException e) { log.error("Unable to connect to MONGODB at host " + contactNode + "; Details:" + e.getMessage()); } catch (MongoException e) { log.error("Unable to connect to MONGODB; Details:" + e.getMessage()); } } }
From source file:iddb.web.security.service.CommonUserService.java
@Override public Subject findUserSession(HttpServletRequest request) { HttpSession session = request.getSession(false); Subject s = null;//from w w w. ja v a 2 s . c o m if (session != null) { s = (Subject) session.getAttribute(SUBJECT); } if (s == null) { log.trace("Lookup cookie trace"); String sessionKey = null; String sessionUser = null; sessionKey = getCookie(request.getCookies(), "iddb-k"); if (sessionKey != null) { sessionUser = getCookie(request.getCookies(), "iddb-u"); } if (sessionKey != null && sessionUser != null) { log.trace("Found cookie trace"); Session localSession = null; try { localSession = findSession(sessionKey, Long.parseLong(sessionUser), request.getRemoteAddr()); } catch (NumberFormatException e) { log.error(e.getMessage()); } if (localSession != null) { if (localSession.getCreated().before(DateUtils.addDays(new Date(), SESSION_LIFE))) { log.trace("Found valid session"); s = findUser(localSession.getUserId()); if (s != null) { session = request.getSession(true); session.setAttribute(SUBJECT, s); session.setAttribute(SESSION_KEY, localSession.getKey()); } } else { log.trace("Session expired"); } } } } else { log.trace("Using subject from session"); } if (s != null) saveLocal(s); return s; }
From source file:com.tupilabs.pbs.parser.QstatQueuesParser.java
@Override public List<Queue> parse(String text) throws ParseException { final List<Queue> queues; if (StringUtils.isNotBlank(text)) { queues = new LinkedList<Queue>(); String separator = "\n"; if (text.indexOf("\r\n") > 0) { separator = "\r\n"; }//from w w w .ja v a 2 s . c o m final String[] lines = text.split(separator); Queue queue = null; for (final String line : lines) { Matcher matcher = PATTERN_QUEUE.matcher(line); if (matcher.matches()) { if (queue != null) { queues.add(queue); } queue = new Queue(); final String name = matcher.group(1); queue.setName(name); } else if (StringUtils.isNotBlank(line)) { String[] temp = Utils.splitFirst(line, CHAR_EQUALS); if (temp.length == 2) { final String key = temp[0].trim().toLowerCase(); final String value = temp[1].trim(); if ("queue_type".equals(key)) { queue.setQueueType(value); } else if ("priority".equals(key)) { try { queue.setPriority(Integer.parseInt(value)); } catch (NumberFormatException nfe) { LOGGER.log(Level.WARNING, "Failed parsing queue priority: " + nfe.getMessage(), nfe); queue.setPriority(-1); } } else if ("total_jobs".equals(key)) { try { queue.setTotalJobs(Integer.parseInt(value)); } catch (NumberFormatException nfe) { LOGGER.log(Level.WARNING, "Failed parsing queue total jobs: " + nfe.getMessage(), nfe); queue.setPriority(-1); } } else if ("state_count".equals(key)) { queue.setStateCount(value); } else if ("mtime".equals(key)) { queue.setMtime(value); } else if ("max_user_run".equals(key)) { try { queue.setMaxUserRun(Integer.parseInt(value)); } catch (NumberFormatException nfe) { LOGGER.log(Level.WARNING, "Failed parsing queue max user run: " + nfe.getMessage(), nfe); queue.setPriority(-1); } } else if ("enabled".equals(key)) { queue.setEnabled(Boolean.parseBoolean(value)); } else if ("started".equals(key)) { queue.setStarted(Boolean.parseBoolean(value)); } else if (key.startsWith("resources_max.")) { queue.getResourcesMax().put(key, value); } else if (key.startsWith("resources_min.")) { queue.getResourcesMin().put(key, value); } else if (key.startsWith("resources_assigned.")) { queue.getResourcesAssigned().put(key, value); } else if (key.startsWith("resources_default.")) { queue.getResourcesDefault().put(key, value); } else { LOGGER.info("Unmmaped key, value: " + key + ", " + value); } } } } if (queue != null) { queues.add(queue); } return queues; } else { return Collections.emptyList(); } }
From source file:de.xwic.appkit.webbase.table.filter.NumberFilter.java
/** * @param type/*from w ww. j av a 2 s .c o m*/ * @param fromText * @return */ private Object getNumber(String type, String fromText) { Object from = null; if (fromText != null && !(fromText = fromText.trim()).isEmpty()) { try { if ("java.lang.Integer".equals(type) || "int".equals(type)) { from = Integer.parseInt(fromText); } else if ("java.lang.Double".equals(type) || "double".equals(type)) { from = Double.parseDouble(fromText); } else if ("java.lang.Long".equals(type) || "long".equals(type)) { from = Long.parseLong(fromText); } } catch (NumberFormatException e) { log.error("Error while getting the number " + e.getMessage(), e); } } return from; }
From source file:ca.nrc.cadc.tap.db.AsciiTableData.java
/** * @return The list of formatted objects representing a row of data. *//*from w ww. j a va2s. c om*/ @Override public List<Object> next() { if (!hasNext()) { throw new IllegalStateException("No more data to read."); } CSVRecord rec = rowIterator.next(); if (rec.size() != columnNames.size()) { throw new IllegalArgumentException( "wrong number of columns (" + rec.size() + ") expected " + columnNames.size()); } try { List<Object> row = new ArrayList<Object>(columnNames.size()); String cell = null; Object value = null; Format format = null; for (int i = 0; i < rec.size(); i++) { cell = rec.get(i); format = columnFormats.get(i); value = format.parse(cell); row.add(value); } return row; } catch (NumberFormatException ex) { throw new IllegalArgumentException("invalid number: " + ex.getMessage()); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.dao.jdbc.ProjectCaseDashboardDAOImpl.java
protected Float getRatio(final String ratio) { if (ratio != null) { try {/*from w w w .j a v a2 s .c o m*/ final String[] ratioTab = ratio.split("/", 2); if ((ratioTab.length == 2) && (Float.parseFloat(ratioTab[1]) > 0.0)) { final Float f = Float.parseFloat(ratioTab[0]) / Float.parseFloat(ratioTab[1]); if (f > 1f) { return 1f; } else { return f; } } } catch (NumberFormatException ne) { logger.info("Error parsing number " + ne.getMessage()); } } return 0f; }
From source file:example.SimpleChaincode.java
@Override public Response invoke(ChaincodeStub stub) { try {//from w w w . j a v a 2 s . c om final List<String> argList = stub.getStringArgs(); final String function = argList.get(0); final String[] args = argList.stream().skip(1).toArray(String[]::new); switch (function) { case "init": return init(stub, args); case "invoke": return invoke(stub, args); case "transfer": return transfer(stub, args); case "put": for (int i = 0; i < args.length; i += 2) stub.putStringState(args[i], args[i + 1]); return newSuccessResponse(); case "del": for (String arg : args) stub.delState(arg); return newSuccessResponse(); case "query": return query(stub, args); default: return newBadRequestResponse(newErrorJson("Unknown function: %s", function)); } } catch (NumberFormatException e) { return newBadRequestResponse(e.toString()); } catch (IllegalArgumentException e) { return newBadRequestResponse(e.getMessage()); } catch (Throwable e) { return newInternalServerErrorResponse(e); } }