List of usage examples for java.lang NumberFormatException toString
public String toString()
From source file:biz.varkon.shelvesom.provider.books.BooksStore.java
private void parsePrices(XmlPullParser parser, Book book) throws IOException, XmlPullParserException { int type;// w w w .j a va 2 s.c om String name; final int depth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } name = parser.getName(); if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) { if (parser.next() == XmlPullParser.TEXT) { String price = parser.getText(); try { if (book.mRetailPrice == null || (book.mRetailPrice != null && Double .valueOf(book.mRetailPrice.substring(1)) > Double.valueOf(price.substring(1)))) { book.mRetailPrice = price; } } catch (NumberFormatException n) { Log.e(LOG_TAG, n.toString()); if (book.mRetailPrice == null) book.mRetailPrice = ""; } } } } }
From source file:biz.varkon.shelvesom.provider.movies.MoviesStore.java
private void parsePrices(XmlPullParser parser, Movie movie) throws IOException, XmlPullParserException { int type;/*from w w w.j a v a 2 s.com*/ String name; final int depth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } name = parser.getName(); if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) { if (parser.next() == XmlPullParser.TEXT) { String price = parser.getText(); try { if (movie.mRetailPrice == null || (movie.mRetailPrice != null && Double .valueOf(movie.mRetailPrice.substring(1)) > Double.valueOf(price.substring(1)))) { movie.mRetailPrice = price; } } catch (NumberFormatException n) { Log.e(LOG_TAG, n.toString()); if (movie.mRetailPrice == null) movie.mRetailPrice = ""; } } } } }
From source file:de.fuberlin.wiwiss.r2r.Mapping.java
public List<String> execFunction(FunctionExecution functionExecution, VariableResults varResults, String datatypeHint) {//from ww w . j a v a 2 s .co m List<Argument> arguments = functionExecution.getArguments(); List<List<String>> realArguments = new ArrayList<List<String>>(); Function function = functionExecution.getFunction(); ///////////// Debug Code -> // System.out.print(function.getURI() + "("); // boolean notFirst = false; //////////// List<String> returnList = null; try { for (Argument argument : arguments) { if (argument instanceof ConstantArgument) { ArrayList<String> arg = new ArrayList<String>(); arg.add(((ConstantArgument) argument).getValue()); realArguments.add(arg); ///////////// Debug code -> // if(notFirst) // System.out.print(", "); // notFirst = true; // System.out.print(arg.get(0)); ///////////// } else if (argument instanceof VariableArgument) { String varName = ((VariableArgument) argument).getVariableName(); //Make the argument List unmodifiable to protect against "defect" functions realArguments.add(Collections.unmodifiableList(varResults.getResults(varName))); } else if (argument instanceof FunctionExecution) { ////////////// Debug Code -> // if(notFirst) // System.out.print(", "); // notFirst = true; ////////////// realArguments.add(execFunction((FunctionExecution) argument, varResults, datatypeHint)); } } returnList = function.execute(realArguments, datatypeHint); ////////////////// Debug code -> // if(returnList.size()>1) { // System.out.print(" ) = ["); // boolean nF = false; // for(String a: returnList) { // if(nF) // System.out.print(", "); // nF=true; // System.out.print(a); // } // System.out.print("]"); // } // else // System.out.print(" = " + returnList.get(0)+ ")"); ////////////////// } catch (NumberFormatException e) { String msg = "Could not execute function <" + function.getURI() + "> correctly: " + e.toString(); throw new FunctionExecutionException(msg, e); } catch (RuntimeException e) { String msg = "Exception while executing function <" + function.getURI() + ">: " + e; throw new FunctionExecutionException(msg, e); } return returnList; }
From source file:org.eclipse.smila.connectivity.framework.crawler.web.http.RobotRulesParser.java
/** * Returns a {@link RobotRuleSet} object which encapsulates the rules parsed from the supplied * <code>robotContent</code>. * /*from ww w . j a v a 2s . co m*/ * @param robotContent * the robot content * * @return the robot rule set */ RobotRuleSet parseRules(final byte[] robotContent) { if (robotContent == null) { return EMPTY_RULES; } final String content = new String(robotContent); final StringTokenizer lineParser = new StringTokenizer(content, "\n\r"); RobotRuleSet bestRulesSoFar = null; int bestPrecedenceSoFar = NO_PRECEDENCE; RobotRuleSet currentRules = new RobotRuleSet(); int currentPrecedence = NO_PRECEDENCE; boolean addRules = false; // in stanza for our robot boolean doneAgents = false; // detect multiple agent lines while (lineParser.hasMoreTokens()) { String line = lineParser.nextToken(); // trim out comments and whitespace final int hashPos = line.indexOf("#"); if (hashPos >= 0) { line = line.substring(0, hashPos); } line = line.trim(); if ((line.length() >= USER_AGENT.length()) && (line.substring(0, USER_AGENT.length()).equalsIgnoreCase(USER_AGENT))) { if (doneAgents) { if (currentPrecedence < bestPrecedenceSoFar) { bestPrecedenceSoFar = currentPrecedence; bestRulesSoFar = currentRules; currentPrecedence = NO_PRECEDENCE; currentRules = new RobotRuleSet(); } addRules = false; } doneAgents = false; String agentNames = line.substring(line.indexOf(COLON) + 1); agentNames = agentNames.trim(); final StringTokenizer agentTokenizer = new StringTokenizer(agentNames); while (agentTokenizer.hasMoreTokens()) { // for each agent listed, see if it's us: final String agentName = agentTokenizer.nextToken().toLowerCase(); final Integer precedenceInt = _robotNames.get(agentName); if (precedenceInt != null) { final int precedence = precedenceInt.intValue(); if ((precedence < currentPrecedence) && (precedence < bestPrecedenceSoFar)) { currentPrecedence = precedence; } } } if (currentPrecedence < bestPrecedenceSoFar) { addRules = true; } } else if ((line.length() >= DISALLOW.length()) && (line.substring(0, DISALLOW.length()).equalsIgnoreCase(DISALLOW))) { doneAgents = true; String path = line.substring(line.indexOf(COLON) + 1); path = path.trim(); try { path = URLDecoder.decode(path, CHARACTER_ENCODING); } catch (final UnsupportedEncodingException e) { LOG.warn("error parsing robots rules- can't decode path: " + path); } if (path.length() == 0) { // "empty rule" if (addRules) { currentRules.clearPrefixes(); } } else { // rule with path if (addRules) { currentRules.addPrefix(path, false); } } } else if ((line.length() >= ALLOW.length()) && (line.substring(0, ALLOW.length()).equalsIgnoreCase(ALLOW))) { doneAgents = true; String path = line.substring(line.indexOf(COLON) + 1); path = path.trim(); if (path.length() == 0) { // "empty rule"- treat same as empty disallow if (addRules) { currentRules.clearPrefixes(); } } else { // rule with path if (addRules) { currentRules.addPrefix(path, true); } } } else if ((line.length() >= CRAWL_DELAY.length()) && (line.substring(0, CRAWL_DELAY.length()).equalsIgnoreCase(CRAWL_DELAY))) { doneAgents = true; long crawlDelay = -1; final String delay = line.substring("Crawl-Delay:".length(), line.length()).trim(); if (delay.length() > 0) { try { crawlDelay = Long.parseLong(delay) * Configuration.MILLIS_PER_SECOND; // sec to millisec } catch (final NumberFormatException exception) { LOG.info("can not parse Crawl-Delay:" + exception.toString()); } currentRules.setCrawlDelay(crawlDelay); } } } if (currentPrecedence < bestPrecedenceSoFar) { bestPrecedenceSoFar = currentPrecedence; bestRulesSoFar = currentRules; } if (bestPrecedenceSoFar == NO_PRECEDENCE) { return EMPTY_RULES; } return bestRulesSoFar; }
From source file:com.hijacker.MainActivity.java
public static ArrayList<Integer> getPIDs(String process_name) { if (process_name == null) return null; Shell shell = getFreeShell();// w w w . ja v a 2 s . co m ArrayList<Integer> list = new ArrayList<>(); shell.run(busybox + " pidof " + process_name + "; echo ENDOFPIDOF"); BufferedReader out = shell.getShell_out(); String buffer = null; try { while (buffer == null) buffer = out.readLine(); while (!buffer.equals("ENDOFPIDOF")) { String[] temp = buffer.split(" "); try { for (String tmp : temp) { list.add(Integer.parseInt(tmp)); } } catch (NumberFormatException e) { Log.e("HIJACKER/getPIDs", "Exception: " + e.toString()); } buffer = out.readLine(); } } catch (IOException e) { Log.e("HIJACKER/getPIDs", "Exception: " + e.toString()); list = null; } shell.done(); return list; }
From source file:us.mn.state.health.lims.common.provider.reports.SampleLabelPrintProvider.java
/** * printLabels() - for SampleLabelPrintProvider * /*w ww . j a v a 2s . co m*/ * @param usd - UserSessionData from request * accessionCount - String of how many accession numbers to generate/print * accessionStart - String of starting accession number range to print * accessionEnd - String of ending accession number range to print * printerName - String of name of printer to use * masterLabels - String of number of master labels to print * itemLabels - String of number of item labels to print * @return String - success or fail */ public String printLabels(HttpServletRequest request, UserSessionData usd, String accessionCount, String accessionStart, String accessionEnd, String printerName, String masterLabels, String itemLabels) { returnedData = validateInput(accessionCount, accessionStart, accessionEnd, printerName, masterLabels, itemLabels); if (!FWD_SUCCESS.equals(returnedData)) return returnedData; initializeLabelProperties(); String[] accList = generateAccessionList(accessionCount, accessionStart, accessionEnd); //bgm added to see if this will fix the error for a record lock when this Sample is added here and // then updated later,within same thread, on another screen.... like in QuickEntry. Transaction tx = HibernateUtil.getSession().beginTransaction(); try { for (int i = 0; i < accList.length; i++) { accessionNumber = accList[i]; initializeLabelData(); populateSampleData(usd); populatePatientData(); updateLabelSampleData(); if (patientService != null) updateLabelPatientData(); //runPrintJobs(); } printBarcodeLabel(accList); tx.commit(); } catch (NumberFormatException nfe) { tx.rollback(); LogEvent.logError("SampleLabelPrintProvider", "printLabels()", StringUtil.getMessageForKey("errors.labelprint.bad.number") + " : " + nfe.toString()); returnedData = FWD_FAIL; } catch (Exception e) { tx.rollback(); e.printStackTrace(); LogEvent.logError("SampleLabelPrintProvider", "printLabels()", e.toString()); returnedData = FWD_FAIL; } finally { HibernateUtil.closeSession(); } return returnedData; }
From source file:com.ereinecke.eatsafe.MainActivity.java
@Override public void onItemSelected(String barcode) { try {/*w w w .j ava2 s .co m*/ long productId = Long.parseLong(barcode); launchProductFragment(productId); } catch (NumberFormatException e) { Log.e(LOG_TAG, "Selected item contains unparseable barcode: " + barcode); Log.e(LOG_TAG, e.toString()); } }
From source file:org.transdroid.daemon.Deluge.DelugeAdapter.java
private void ensureVersion(Log log) throws DaemonException { if (version > 0) { return;//from ww w .j a va2s . com } // We still need to retrieve the version number from the server // Do this by getting the web interface main html page and trying to parse the version number // Format is something like '<title>Deluge: Web UI 1.3.6</title>' if (httpclient == null) { initialise(); } try { HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl() + "/")); String main = HttpHelper.convertStreamToString(response.getEntity().getContent()); String titleStartText = "<title>Deluge: Web UI "; String titleEndText = "</title>"; int titleStart = main.indexOf(titleStartText); int titleEnd = main.indexOf(titleEndText, titleStart); if (titleStart >= 0 && titleEnd > titleStart) { // String found: now parse a version like 2.9.7 as a number like 20907 (allowing 10 places for each .) String[] parts = main.substring(titleStart + titleStartText.length(), titleEnd).split("\\."); if (parts.length > 0) { version = Integer.parseInt(parts[0]) * 100 * 100; if (parts.length > 1) { version += Integer.parseInt(parts[1]) * 100; if (parts.length > 2) { // For the last part only read until a non-numeric character is read // For example version 3.0.0-alpha5 is read as version code 30000 String numbers = ""; for (char c : parts[2].toCharArray()) { if (Character.isDigit(c)) // Still a number; add it to the numbers string { numbers += Character.toString(c); } else { // No longer reading numbers; stop reading break; } } version += Integer.parseInt(numbers); return; } } } } } catch (NumberFormatException e) { log.d(LOG_NAME, "Error parsing the Deluge version code as number: " + e.toString()); // Continue though, ignoring the version number } catch (Exception e) { log.d(LOG_NAME, "Error: " + e.toString()); throw new DaemonException(ExceptionType.ConnectionError, e.toString()); } // Unable to establish version number; assume an old version by setting it to version 1 version = 10000; }
From source file:com.forrestguice.suntimeswidget.LocationConfigView.java
public WidgetSettings.Location getLocation() { String name = text_locationName.getText().toString(); String latitude = text_locationLat.getText().toString(); String longitude = text_locationLon.getText().toString(); try {//from w ww.jav a 2 s . co m @SuppressWarnings("UnusedAssignment") BigDecimal lat = new BigDecimal(latitude); @SuppressWarnings("UnusedAssignment") BigDecimal lon = new BigDecimal(longitude); } catch (NumberFormatException e) { Log.e("getLocation", "invalid location! falling back to default; " + e.toString()); name = WidgetSettings.PREF_DEF_LOCATION_LABEL; latitude = WidgetSettings.PREF_DEF_LOCATION_LATITUDE; longitude = WidgetSettings.PREF_DEF_LOCATION_LONGITUDE; } return new WidgetSettings.Location(name, latitude, longitude); }
From source file:org.lockss.servlet.DaemonStatus.java
private void doXmlStatusTable() throws IOException, XmlDomBuilder.XmlDomException { // By default, XmlDomBuilder will produce UTF-8. Must set content type // *before* calling getWriter() resp.setContentType("text/xml; charset=UTF-8"); PrintWriter wrtr = resp.getWriter(); try {//from w w w . j a va 2 s. c om StatusTable statTable = makeTable(); XmlStatusTable xmlTable = new XmlStatusTable(statTable); String over = req.getParameter("outputVersion"); if (over != null) { try { int ver = Integer.parseInt(over); xmlTable.setOutputVersion(ver); } catch (NumberFormatException e) { log.warning("Illegal outputVersion: " + over + ": " + e.toString()); } } Document xmlTableDoc = xmlTable.getTableDocument(); XmlDomBuilder.serialize(xmlTableDoc, wrtr); } catch (Exception e) { XmlDomBuilder xmlBuilder = new XmlDomBuilder(XmlStatusConstants.NS_PREFIX, XmlStatusConstants.NS_URI, "1.0"); Document errorDoc = XmlDomBuilder.createDocument(); org.w3c.dom.Element rootElem = xmlBuilder.createRoot(errorDoc, XmlStatusConstants.ERROR); if (e instanceof StatusService.NoSuchTableException) { XmlDomBuilder.addText(rootElem, "No such table: " + e.toString()); } else { String emsg = e.toString(); StringBuilder buffer = new StringBuilder("Error getting table: "); buffer.append(emsg); buffer.append("\n"); buffer.append(StringUtil.trimStackTrace(emsg, StringUtil.stackTraceString(e))); XmlDomBuilder.addText(rootElem, buffer.toString()); } XmlDomBuilder.serialize(errorDoc, wrtr); return; } }