List of usage examples for java.lang NumberFormatException printStackTrace
public void printStackTrace()
From source file:com.oak_yoga_studio.controller.AdminController.java
/** * /* www .ja va 2 s . c o m*/ * @param binder */ @InitBinder protected void initBinder(WebDataBinder binder) { // binder.registerCustomEditor(Integer.class, "totalSeat", // new PropertyEditorSupport() { // // @Override // public void setAsText(String text) { // Integer totalSeat= Integer.parseInt(text); // setValue(totalSeat); // } // }); // // binder.registerCustomEditor(Long.class, "id", // new PropertyEditorSupport() { // // @Override // public void setAsText(String text) { // Long id= Long.parseLong(text); // setValue(id); // } // }); // // binder.registerCustomEditor(List.class, "prerequisites", new CustomCollectionEditor(List.class) { @Override protected Object convertElement(Object element) { Integer id = null; if (element instanceof String && !((String) element).equals("")) { // From the JSP 'element' will be a String try { id = Integer.parseInt((String) element); } catch (NumberFormatException e) { System.out.println("Element was " + ((String) element)); e.printStackTrace(); } } else if (element instanceof Integer) { // From the database 'element' will be a int id = (Integer) element; } return id != null ? courseService.getCourseById(id) : null; } }); binder.registerCustomEditor(Faculty.class, "professor", new PropertyEditorSupport() { @Override public void setAsText(String facultyID) { Faculty faculty = facultyServcie.getFacultyById(Integer.parseInt(facultyID)); setValue(faculty); } }); binder.registerCustomEditor(Course.class, "course", new PropertyEditorSupport() { @Override public void setAsText(String courseID) { Course course = courseService.getCourseById(Integer.parseInt(courseID)); setValue(course); } }); }
From source file:eu.trentorise.smartcampus.ac.provider.services.AcProviderServiceImpl.java
/** * Returns true if the user can access the specified resource. Currently, the resource should * correspond to the entityId as stored in the Social Engine entity space. * /*from w w w .java 2 s . com*/ * @return true if the read permission is granted for the resource * @throws AcServiceException */ @Override public boolean canReadResource(String authToken, String resourceId) throws AcServiceException { User user = getUserByToken(authToken); if (user == null) { throw new AcServiceException("User matching the token " + authToken + " is not found."); } try { return socialManager.checkResourceAccess(user.getSocialId(), Long.parseLong(resourceId)); } catch (NumberFormatException e) { throw new AcServiceException("Resource ID should be a number."); } catch (Exception e) { e.printStackTrace(); throw new AcServiceException("Error reading the access rights: " + e.getMessage()); } }
From source file:ape.CorruptCommand.java
/** * This method overrides the abstract function declared in the ApeCommand class * which actual implements the event// w w w . j a v a 2 s . c om */ @Override protected boolean runImpl(String[] args) throws ParseException, IOException { datatype = args[0]; try { size = Integer.parseInt(args[1]); offset = Integer.parseInt(args[2]); } catch (NumberFormatException t) { System.out.println("Unable to parse the size or offset given as an integer."); Main.logger.info("Unable to parse the size or offset given as an integer."); t.printStackTrace(); Main.logger.info(t); return false; } if (Main.VERBOSE) { System.out.println("VERBOSE: Data type is " + args[0]); System.out.println("VERBOSE: Size of corruption is " + size); System.out.println("VERBOSE: Offset is " + offset); } if (!corrupt(null)) { System.out.println("Corrupting block file unsuccessful"); return false; } return true; }
From source file:captureplugin.drivers.dreambox.connector.DreamboxConnector.java
/** * Tries to parse a Long//from w w w . jav a 2 s . c o m * * @param longStr * String with Long-Value * @return long-Value or -1 */ private long getLong(String longStr) { if (longStr.contains(".")) { longStr = StringUtils.substringBefore(longStr, "."); } try { return Long.parseLong(longStr); } catch (NumberFormatException e) { e.printStackTrace(); } return -1; }
From source file:org.apache.cordova.X5CordovaActivity.java
@SuppressWarnings({ "deprecation", "ResourceType" }) protected void createViews() { //Why are we setting a constant as the ID? This should be investigated appView.getView().setId(100);// ww w . j ava2s.com appView.getView().setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setContentView(appView.getView()); if (preferences.contains("BackgroundColor")) { try { int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK); // Background of activity: appView.getView().setBackgroundColor(backgroundColor); } catch (NumberFormatException e) { e.printStackTrace(); } } appView.getView().requestFocusFromTouch(); }
From source file:org.occiware.clouddesigner.occi.linkeddata.connector.LdprojectConnector.java
/** * //from w ww.j a v a 2s. c om * @param resource must come from getExistingOrNew() */ private void retrieveAttributes(DCResource resource) { this.setName((String) resource.get("dcmpv:name")); @SuppressWarnings("unchecked") List<String> frozenModelNames = (List<String>) resource.get("dcmp:frozenModelNames"); this.setLifecycle( frozenModelNames != null && frozenModelNames.contains("*") ? Lifecycle.PUBLISHED : Lifecycle.DRAFT); Boolean isRobust = (Boolean) resource.get("dcmpvdb:robust"); this.setRobustness(isRobust != null && isRobust ? Robustness.CLUSTER : Robustness.NONE); // TODO Robustness.NODE vs high write ? ///resource.set("dcmpvdb:uri", this.dburi); // rather using links : String ldDbUri = (String) resource.get("dcmpvdb:uri"); if (ldDbUri != null) { Pattern p = Pattern.compile("mongodb://(.+):(.+)/(.+)"); Matcher m = p.matcher(ldDbUri); if (m.find()) { String hostname = m.group(1); String portString = m.group(2); String database = m.group(3); int port; try { port = Integer.parseInt(portString); } catch (NumberFormatException e) { e.printStackTrace(); port = 27017; // mongo default } List<Link> lddLinks = this.links.stream().filter(l -> l instanceof Lddatabaselink) .collect(Collectors.toList()); Lddatabaselink sameLddLinkFound = null; List<Lddatabaselink> wrongLddLinks = new ArrayList<Lddatabaselink>(3); for (Link link : lddLinks) { Lddatabaselink lddLink = (Lddatabaselink) link; Compute customSecondaryCompute = (Compute) link.getTarget(); // should be a Compute if (customSecondaryCompute != null && hostname.equals(customSecondaryCompute.getHostname())) { if (port == lddLink.getPort() && database.equals(lddLink.getDatabase())) { sameLddLinkFound = lddLink; continue; } } wrongLddLinks.add(lddLink); } // TODO delete wrongLddLinks (but not their Computes) if (sameLddLinkFound == null) { // TODO find compute in conf (or ask provisioning server ???) or create it // and create link } // else nothing to do } } // TODO discovery of all projects ?!? /*LinkedHashSet<String> lvp = new LinkedHashSet<String>(); @SuppressWarnings("unchecked") List<String> lvpFound = (List<String>) resource.get("dcmp:localVisibleProjects"); if (lvpFound == null) { lvp = new LinkedHashSet<String>(); lvp.add(UriHelper.buildUri(ldContainerUrl, "dcmp:Project_0", "oasis.meta")); // all projects must see metamodel } else { lvp = new LinkedHashSet<String>(lvpFound); } List<String> ldpLinkTargetProjectUris = this.links.stream() .filter(l -> l instanceof Ldprojectlink && l.getTarget() instanceof Ldproject) .map(ldpl -> UriHelper.buildUri(ldContainerUrl, "dcmp:Project_0", ((Ldproject) ldpl.getTarget()).getName())) .collect(Collectors.toList()); lvp.addAll(ldpLinkTargetProjectUris); resource.set("dcmp:localVisibleProjects", lvp);*/ }
From source file:com.tesora.dve.sql.logfile.LogFileTest.java
private static Integer getNoisyInterval() { final String any = System.getProperty(NOISY_INTERVAL); if ((any == null) || "".equals(any)) { return null; }//www . ja v a2 s . c om try { return Integer.parseInt(any); } catch (final NumberFormatException nfe) { nfe.printStackTrace(); return null; } }
From source file:de.fuberlin.wiwiss.marbles.loading.CacheController.java
/** * Determines whether the cache holds a valid copy of an URL's data * @param url The URL of interest/*w ww. ja v a 2 s .com*/ * @return true, if a valid copy is present */ public boolean hasURLData(String url) { boolean hasData = false; RepositoryConnection metaDataConn = null; try { metaDataConn = metaDataRepository.getConnection(); URI metaUrlContext = metaDataRepository.getValueFactory().createURI(url); Date now = new Date(); /* This is always set, so if it's not set, the URL has not been loaded */ String date = getCachedHeaderDataValue(metaDataConn, metaUrlContext, "date"); if (date == null) return false; Date dateRetrieved = DateUtil.parseDate(date); /* * Due to performance considerations, don't retrieve an URL * twice within 24 hours (response headers are deliberately ignored here!!) */ if (dateRetrieved.getTime() + 1000 * 60 * 60 * 24 > now.getTime()) return true; /* * Check several caching indicators * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html */ String pragma = getCachedHeaderDataValue(metaDataConn, metaUrlContext, "pragma"); if ((pragma != null && pragma.equalsIgnoreCase("no-cache"))) return false; Header cacheControlHeader = getCachedHeaderData(metaDataConn, metaUrlContext, "cache-control"); if (cacheControlHeader != null) { for (HeaderElement element : cacheControlHeader.getElements()) { if (element.getName().equalsIgnoreCase("private") || element.getName().equalsIgnoreCase("no-cache") || element.getName().equalsIgnoreCase("no-store") || element.getName().equalsIgnoreCase("must-revalidate") || element.getName().equalsIgnoreCase("proxy-revalidate")) return false; if (element.getName().equalsIgnoreCase("max-age") || element.getName().equalsIgnoreCase("s-max-age")) { try { long maxAge = Long.parseLong(element.getValue()); Date expiryDate = new Date(dateRetrieved.getTime() + maxAge * 1000); if (now.after(expiryDate)) return false; } catch (NumberFormatException e) { e.printStackTrace(); } } } } String expires = getCachedHeaderDataValue(metaDataConn, metaUrlContext, "expires"); if (expires != null) { Date expiryDate = DateUtil.parseDate(expires); if (now.after(expiryDate)) return false; } hasData = true; } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } catch (DateParseException e) { e.printStackTrace(); } finally { if (metaDataConn != null) try { metaDataConn.close(); } catch (RepositoryException e) { e.printStackTrace(); } } return hasData; }
From source file:org.apache.hadoop.chukwa.database.DataExpiration.java
public void dropTables(long start, long end) { String cluster = System.getProperty("CLUSTER"); if (cluster == null) { cluster = "unknown"; }/*from w w w . j a v a2 s . c o m*/ DatabaseWriter dbw = new DatabaseWriter(cluster); try { HashMap<String, String> dbNames = dbc.startWith("report.db.name."); Iterator<String> ki = dbNames.keySet().iterator(); while (ki.hasNext()) { String name = ki.next(); String tableName = dbNames.get(name); String[] tableList = dbc.findTableName(tableName, start, end); for (String tl : tableList) { log.debug("table name: " + tableList[0]); try { String[] parts = tl.split("_"); int partition = Integer.parseInt(parts[parts.length - 2]); String table = ""; for (int i = 0; i < parts.length - 2; i++) { if (i != 0) { table = table + "_"; } table = table + parts[i]; } partition = partition - 3; String dropPartition = "drop table if exists " + table + "_" + partition + "_" + parts[parts.length - 1]; dbw.execute(dropPartition); partition--; if (partition >= 0) { dropPartition = "drop table if exists " + table + "_" + partition + "_" + parts[parts.length - 1]; dbw.execute(dropPartition); } } catch (NumberFormatException e) { log.error("Error in parsing table partition number, skipping table:" + tableList[0]); } catch (ArrayIndexOutOfBoundsException e) { log.debug( "Skipping table:" + tableList[0] + ", because it has no partition configuration."); } } } dbw.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:cc.twittertools.download.AsyncEmbeddedJsonStatusBlockCrawler.java
public void fetch() throws IOException { long start = System.currentTimeMillis(); LOG.info("Processing " + file); int cnt = 0;//from w w w. j av a2s.c o m BufferedReader data = null; try { data = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line; while ((line = data.readLine()) != null) { try { String[] arr = line.split("\t"); long id = Long.parseLong(arr[0]); String username = (arr.length > 1) ? arr[1] : "a"; String url = getUrl(id, username); connections.incrementAndGet(); crawlURL(url, new TweetFetcherHandler(id, username, url, 0, !this.noFollow, line)); cnt++; if (cnt % TWEET_BLOCK_SIZE == 0) { LOG.info(cnt + " requests submitted"); } } catch (NumberFormatException e) { // parseLong continue; } } } catch (IOException e) { e.printStackTrace(); } finally { data.close(); } // Wait for the last requests to complete. LOG.info("Waiting for remaining requests (" + connections.get() + ") to finish!"); for (int i = 0; i < 10; i++) { if (connections.get() == 0) { break; } try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } asyncHttpClient.close(); long end = System.currentTimeMillis(); long duration = end - start; LOG.info("Total request submitted: " + cnt); LOG.info(crawl.size() + " tweets fetched in " + duration + "ms"); LOG.info("Writing tweets..."); int written = 0; OutputStreamWriter out = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(output)), "UTF-8"); for (Map.Entry<Long, String> entry : crawl.entrySet()) { written++; out.write(entry.getValue() + "\n"); } out.close(); LOG.info(written + " statuses written."); if (this.repair != null) { LOG.info("Writing repair data file..."); written = 0; out = new OutputStreamWriter(new FileOutputStream(repair), "UTF-8"); for (Map.Entry<Long, String> entry : crawl_repair.entrySet()) { written++; out.write(entry.getValue() + "\n"); } out.close(); LOG.info(written + " statuses need repair."); } LOG.info("Done!"); }