List of usage examples for java.lang NumberFormatException printStackTrace
public void printStackTrace()
From source file:MenuItemChooser.java
private void updateQtyOrdered() { try {//w ww . j a v a2 s . com String val = qty.getText(); items[currMenuItem].qtyOrdered = (new Integer(val)).intValue(); } catch (NumberFormatException e) { e.printStackTrace(); } }
From source file:edu.hm.muse.controller.Logincontroller.java
@RequestMapping(value = "/adminlogin.secu", method = RequestMethod.POST) public ModelAndView doAdminLogin(@RequestParam(value = "mpwd", required = false) String mpwd, @RequestParam(value = "csrftoken", required = false) String csrfParam, HttpServletResponse response, HttpSession session) {// w w w . j av a 2s . c o m if (null == mpwd || mpwd.isEmpty()) { throw new SuperFatalAndReallyAnnoyingException( "I can not process, because the requestparam mpwd is empty or null or something like this"); } String sql = "select count (*) from M_ADMIN where mpwd = ?"; try { String digest = calculateSHA256(new ByteArrayInputStream(mpwd.getBytes("UTF8"))); int res = 0; res = jdbcTemplate.queryForInt(sql, new Object[] { digest }, new int[] { Types.VARCHAR }); Integer csrfTokenSess = (Integer) session.getAttribute("csrftoken"); if (res != 0 && csrfParam != null && !csrfParam.isEmpty() && csrfTokenSess != null) { Integer csrfParamToken = Integer.parseInt(csrfParam); if (csrfParamToken.intValue() == csrfTokenSess.intValue()) { SecureRandom random = new SecureRandom(); int token = random.nextInt(); session.setAttribute("user", "admin"); session.setAttribute("login", true); session.setAttribute("admintoken", token); response.addCookie(new Cookie("admintoken", String.valueOf(token))); session.removeAttribute("csrftoken"); return new ModelAndView("redirect:adminintern.secu"); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (ClassCastException ccastEx) { ccastEx.printStackTrace(); } catch (NumberFormatException nfoEx) { nfoEx.printStackTrace(); } catch (DataAccessException e) { throw new SuperFatalAndReallyAnnoyingException( String.format("Sorry but %sis a bad grammar or has following problem %s", sql, e.getMessage())); } ModelAndView mv = returnToAdminLogin(session); return mv; }
From source file:io.isoft.reg.controller.TimerController.java
/** * Simulates a slow server response by delaying a specified number of seconds * @return done message//from w w w.jav a 2s.com */ @RequestMapping(value = "delay/{seconds}", method = RequestMethod.GET) public String delay(@PathVariable String seconds) { int delay = 15; try { delay = Integer.parseInt(seconds); logger.info("Delaying response by " + delay + " seconds"); } catch (NumberFormatException e) { logger.info("Bad input. Defaulting to " + delay + " seconds delay"); } try { Thread.sleep(delay * 1000); } catch (InterruptedException e) { e.printStackTrace(); } return "Response delayed by " + delay + " seconds"; }
From source file:com.drevelopment.couponcodes.canary.coupon.CanaryCouponHandler.java
@Override public HashMap<Integer, Integer> itemStringToHash(String args, CommandSender sender) { HashMap<Integer, Integer> ids = new HashMap<Integer, Integer>(); String[] sp = args.split(","); try {//from www.j a v a2s . co m for (int i = 0; i < sp.length; i++) { int a = 0; if (NumberUtils.isNumber(sp[i].split(":")[0])) { a = Integer.parseInt(sp[i].split(":")[0]); } else { if (Canary.factory().getItemFactory().newItem(sp[i].split(":")[0]) != null) { a = Canary.factory().getItemFactory().newItem(sp[i].split(":")[0]).getId(); } else { a = 1; } } int b = Integer.parseInt(sp[i].split(":")[1]); ids.put(a, b); } } catch (NumberFormatException e) { e.printStackTrace(); } return ids; }
From source file:com.hunchee.haystack.server.resources.gae.GaeStoresResource.java
@Override public JsonRepresentation create(JsonRepresentation representation) { String id = getQueryValue("id"); String type = getQueryValue("type"); try {/*from w w w . j a va2 s . c o m*/ Preconditions.checkNotNull(id, "Id cannot be null"); Preconditions.checkNotNull(id, "Type cannot be null"); Long longId = Long.valueOf(id); Long userId = webTokenService.readUserIdFromToken(clientToken); User user = userService.read(userId); Preconditions.checkNotNull(user, "No associated with token given: " + clientToken); JSONObject object = representation.getJsonObject(); Map map = JSONUtil.parse(object); GenericJson persistence = new GenericJson(longId, type, map, user); storeService.add(persistence); } catch (NumberFormatException e) { setStatus(Status.CLIENT_ERROR_BAD_REQUEST); } catch (NullPointerException e) { setStatus(Status.CLIENT_ERROR_BAD_REQUEST); e.printStackTrace(); } catch (Exception e) { setStatus(Status.SERVER_ERROR_INTERNAL); e.printStackTrace(); } return null; }
From source file:jp.g_aster.social.action.EventAction.java
/** * ?QR????//from w w w . j a va2s. co m * @return */ public ActionResult showQRCode() { if (!this.isLogin()) { log.info("???????????"); return new Redirect("/"); } User user = (User) this.sessionScope.get("user"); try { this.stampDto = eventService.getQRImageUrl(user.getId(), Integer.parseInt(this.eventId), Integer.parseInt(this.stampId)); } catch (NumberFormatException e) { e.printStackTrace(); return new Forward("error.jsp"); } catch (DataNotFoundException e) { e.printStackTrace(); return new Forward("error.jsp"); } return new Forward("viewQRCode.jsp"); }
From source file:gov.nih.nci.system.web.struts.action.UpdateAction.java
public Object convertValue(Class klass, Object value) throws Exception { String fieldType = klass.getName(); Object convertedValue = null; try {//from w w w. j a va2s.c o m if (fieldType.equals("java.lang.Long")) { convertedValue = new Long((String) value); } else if (fieldType.equals("java.lang.Integer")) { convertedValue = new Integer((String) value); } else if (fieldType.equals("java.lang.String")) { convertedValue = value; } else if (fieldType.equals("java.lang.Float")) { convertedValue = new Float((String) value); } else if (fieldType.equals("java.lang.Double")) { convertedValue = new Double((String) value); } else if (fieldType.equals("java.lang.Boolean")) { convertedValue = new Boolean((String) value); } else if (fieldType.equals("java.util.Date")) { SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); convertedValue = format.parse((String) value); } else if (fieldType.equals("java.net.URI")) { convertedValue = new URI((String) value); } else if (fieldType.equals("java.lang.Character")) { convertedValue = new Character(((String) value).charAt(0)); } else if (klass.isEnum()) { Class enumKlass = Class.forName(fieldType); convertedValue = Enum.valueOf(enumKlass, (String) value); } else { throw new Exception("type mismatch - " + fieldType); } } catch (NumberFormatException e) { e.printStackTrace(); throw new Exception(e.getMessage()); } catch (Exception ex) { log.error("ERROR : " + ex.getMessage()); throw ex; } return convertedValue; }
From source file:dkpro.similarity.algorithms.lexical.string.CosineSimilarity.java
public CosineSimilarity(WeightingModeIdf modeIdf, NormalizationMode normMode, String idfScoresFile) { HashMap<String, Double> idfValues = null; if (idfScoresFile != null) { idfValues = new HashMap<String, Double>(); try {/*from ww w. j av a 2 s .co m*/ for (String line : FileUtils.readLines(new File(idfScoresFile))) { if (line.length() > 0) { String[] cols = line.split("\t"); idfValues.put(cols[0], Double.parseDouble(cols[1])); } } } catch (NumberFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { idfValues = null; } initialize(null, modeIdf, normMode, idfValues); }
From source file:dkpro.similarity.algorithms.lexical.string.CosineSimilarity.java
public CosineSimilarity(WeightingModeTf modeTf, WeightingModeIdf modeIdf, NormalizationMode normMode, String idfScoresFile) {//from w ww . ja va2 s. c om HashMap<String, Double> idfValues; if (idfScoresFile != null) { idfValues = new HashMap<String, Double>(); try { for (String line : FileUtils.readLines(new File(idfScoresFile))) { if (line.length() > 0) { String[] cols = line.split("\t"); idfValues.put(cols[0], Double.parseDouble(cols[1])); } } } catch (NumberFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { idfValues = null; } initialize(modeTf, modeIdf, normMode, idfValues); }
From source file:net.refractions.udig.catalog.wmsc.server.TileImageReadWriter.java
/** * Check the tiles last modified time + max cache time v.s. the current time. If its before the * current time the tile is considered out-dated and should be pulled from the server. * /*from w ww . java 2 s . co m*/ * @param tile The Tile Object * @param tileFile the tile image File * @return true if the tile is considered out-dated, false otherwise */ public boolean isTileStale(Tile tile, String filetype) { String filename = getTileFileName(tile, filetype); File tileFile = new File(filename); String cacheFilename = getCacheFilename(tile); File cacheFile = new File(cacheFilename); if (cacheFile.exists()) { try { String persistedCacheAge = FileUtils.readFileToString(cacheFile); if (persistedCacheAge != null && !"".equals(persistedCacheAge)) { //$NON-NLS-1$ Long cacheTimeLong = Long.parseLong(persistedCacheAge); Date cacheTime = new Date(tileFile.lastModified() + (cacheTimeLong * 1000)); if (cacheTime.before(new Date(System.currentTimeMillis()))) { return true; } } else { /* * if we get to here the cache file might have been written without a max cache * age, or corrupted; lets assume the tile is stale */ return true; } } catch (IOException e) { e.printStackTrace(); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } } return false; }