List of usage examples for java.lang Exception getLocalizedMessage
public String getLocalizedMessage()
From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java
public static ArrayList<ITransportationInfo> getNext3Arrivals(String stationFrom, String stationTo, String line, Context context) {/*from w w w. j ava 2 s . c o m*/ ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>(); try { String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename); JsonNode actualObj = Util.stringToJsonNode(bufferString); JsonNode lines = actualObj.get("timetable"); // find the data for the current transportation line for (int i = 0; i < lines.size(); i++) { JsonNode lineJson = lines.get(i); String[] sublines = line.split(","); for (int ii = 0; ii < sublines.length; ii++) { if (lineJson.get("line").asText().equalsIgnoreCase(sublines[ii].trim())) { int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (day == 1) day = 6; else day -= 2; int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int minute = Calendar.getInstance().get(Calendar.MINUTE); JsonNode stationData = null; if ((day == 4 || day == 5) && isFridaySaturdayNight(lineJson.get("night-after-friday-saturday"), hour)) { // night after Friday or Saturday stationData = lineJson.get("night-after-friday-saturday"); } else if (day < 5) { // weekdays stationData = lineJson.get("weekdays"); } else { // weekend stationData = lineJson.get("weekend"); } JsonNode stations = stationData.get("data"); int[] AStationMinutes = null, BStationMinutes = null; // find the data for the start and end station and choose the direction direction = NOT_SET; for (int j = 0; j < stations.size(); j++) { JsonNode st = stations.get(j); if (st.get("station").asText().equalsIgnoreCase(stationFrom) && direction == NOT_SET && AStationMinutes == null) { direction = DEPARTURE; AStationMinutes = getMinutesArray(st.get("departure").asText()); } else if (st.get("station").asText().equalsIgnoreCase(stationFrom) && AStationMinutes == null) { AStationMinutes = getMinutesArray(st.get("arrival").asText()); break; } else if (st.get("station").asText().equalsIgnoreCase(stationTo) && direction == NOT_SET && BStationMinutes == null) { direction = ARRIVAL; BStationMinutes = getMinutesArray(st.get("departure").asText()); } else if (st.get("station").asText().equalsIgnoreCase(stationTo) && BStationMinutes == null) { BStationMinutes = getMinutesArray(st.get("arrival").asText()); break; } } if (AStationMinutes == null || BStationMinutes == null) continue; JsonNode subLines = direction == DEPARTURE ? stationData.get("departure") : stationData.get("arrival"); JsonNode subLine = subLines.get(0); if (hasTrain(hour, subLine.get("night").asText(), subLine.get("day").asText())) { int count = 0; for (int k = 0; k < AStationMinutes.length; k++) { if (minute <= AStationMinutes[k]) { int arrivalHour = hour; int time = BStationMinutes[k] - AStationMinutes[k]; if (AStationMinutes[k] > BStationMinutes[k]) { arrivalHour++; time = 60 - AStationMinutes[k] + BStationMinutes[k]; } ret.add(new STrainData( (hour < 10 ? "0" + hour : "" + hour) + ":" + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k] : "" + AStationMinutes[k]), (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":" + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k] : "" + BStationMinutes[k]), time)); if (++count == 3) break; } } // second pass to get the times for the next hour hour++; for (int k = 0; k < AStationMinutes.length && count < 3; k++) { int arrivalHour = hour; int time = BStationMinutes[k] - AStationMinutes[k]; if (AStationMinutes[k] > BStationMinutes[k]) { arrivalHour++; time = 60 - AStationMinutes[k] + BStationMinutes[k]; } ret.add(new STrainData( (hour < 10 ? "0" + hour : "" + hour) + ":" + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k] : "" + AStationMinutes[k]), (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":" + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k] : "" + BStationMinutes[k]), time)); } } return ret; } } } } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return ret; }
From source file:gov.nasa.arc.geocam.talk.UIUtils.java
/** * Display an exception at the log and to the user via {@link Toast}. * * @param context the context//w w w . j a va 2s . c o m * @param e the e * @param additionalMessage the additional message */ public static void displayException(Context context, Exception e, String additionalMessage) { Log.e("Talk", additionalMessage, e); StringBuilder sb = new StringBuilder(); if (additionalMessage != null) { sb.append(additionalMessage + ": "); } if (e.getLocalizedMessage() != null) { sb.append(e.getLocalizedMessage()); } Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show(); }
From source file:biz.wolschon.finance.jgnucash.actions.FileBugInBrowserAction.java
/** //from w ww. j a v a2s .c om * Open the given URL in the default-browser. * @param url the URL to open * @return false if it did not work */ @SuppressWarnings("unchecked") public static boolean showDocument(final URL url) { if (myJNLPServiceManagerObject == null) { myJNLPServiceManagerObject = getJNLPServiceManagerObject(); } // we cannot use JNLP -> make an educated guess if (myJNLPServiceManagerObject == null) { try { String osName = System.getProperty("os.name"); if (osName.startsWith("Mac OS")) { Class fileMgr = Class.forName("com.apple.eio.FileManager"); Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class }); openURL.invoke(null, new Object[] { url }); } else if (osName.startsWith("Windows")) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); } else { //assume Unix or Linux String[] browsers = { "x-www-browser", "firefox", "iceweasle", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String browser = null; for (int count = 0; count < browsers.length && browser == null; count++) { if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0) { browser = browsers[count]; } if (browser == null) { return false; } else { Runtime.getRuntime().exec(new String[] { browser, url.toString() }); return true; } } } } catch (Exception e) { LOGGER.error("Error attempting to launch web browser natively.", e); JOptionPane.showMessageDialog(null, "Error attempting to launch web browser:\n" + e.getLocalizedMessage()); } } if (myJNLPServiceManagerObject != null) { try { Method method = myJNLPServiceManagerObject.getClass().getMethod("showDocument", new Class[] { URL.class }); Boolean resultBoolean = (Boolean) method.invoke(myJNLPServiceManagerObject, new Object[] { url }); return resultBoolean.booleanValue(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error attempting to launch web browser:\n" + ex.getLocalizedMessage()); } } return false; }
From source file:com.oracle.pgbu.common.testcase.CommonBaseTestCase.java
/** * Close all instance of browser/*from ww w . jav a 2 s .c o m*/ * */ public static void killBrowserProcess() { try { String os = System.getProperty("os.name"); if (os.contains("Windows")) { logger.info("About to clean browsers - kill any existing browsers"); //Kill ALL instances of iexplorer.exe in Task Manager Runtime.getRuntime().exec("taskkill /F /IM iexplore.exe"); Runtime.getRuntime().exec("taskkill /F /IM chrome.exe"); Runtime.getRuntime().exec("taskkill /F /IM firefox.exe"); Runtime.getRuntime().exec("taskkill /F /IM safari.exe"); } } catch (Exception e) { logger.info("Exception occured while deleting open browser tasks " + e.getLocalizedMessage()); } }
From source file:it.geosolutions.geobatch.figis.intersection.Utilities.java
/********* * this method takes a wfs url and download the features as a zip file into * the dest folder/* w w w.java 2 s . co m*/ * * @param textUrl * the URL where finding features * @param dest * the folder where to save the zip file * @param filename * the data to download * @throws MalformedURLException * @throws IOException */ private static void saveZipToLocal(String textUrl, String dest, String filename) throws MalformedURLException, IOException { OutputStream destinationStream = null; InputStream sourceStream = null; try { sourceStream = new java.io.BufferedInputStream(new java.net.URL(textUrl).openStream()); File destFile = new File(dest + "/" + filename + ".zip"); if (destFile.exists()) { if (!destFile.delete()) { throw new IOException("'destFile' " + destFile.getAbsolutePath() + " already exists and it was not possible to remove it!"); } } destinationStream = new BufferedOutputStream(new FileOutputStream(destFile)); IOUtils.copyStream(sourceStream, destinationStream, true, true); } catch (Exception e) { LOGGER.error(e.getLocalizedMessage(), e); } finally { // release if (sourceStream != null) { org.apache.commons.io.IOUtils.closeQuietly(sourceStream); } if (destinationStream != null) { org.apache.commons.io.IOUtils.closeQuietly(destinationStream); } } }
From source file:CB_Core.GCVote.GCVote.java
public static ArrayList<RatingData> GetRating(String User, String password, ArrayList<String> Waypoints) { ArrayList<RatingData> result = new ArrayList<RatingData>(); String data = "userName=" + User + "&password=" + password + "&waypoints="; for (int i = 0; i < Waypoints.size(); i++) { data += Waypoints.get(i);//from ww w.ja v a 2 s. com if (i < (Waypoints.size() - 1)) data += ","; } try { HttpPost httppost = new HttpPost("http://gcvote.de/getVotes.php"); httppost.setEntity(new ByteArrayEntity(data.getBytes("UTF8"))); // Log.info(log, "GCVOTE-Post" + data); // Execute HTTP Post Request String responseString = Execute(httppost); // Log.info(log, "GCVOTE-Response" + responseString); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(responseString)); Document doc = db.parse(is); NodeList nodelist = doc.getElementsByTagName("vote"); for (Integer i = 0; i < nodelist.getLength(); i++) { Node node = nodelist.item(i); RatingData ratingData = new RatingData(); ratingData.Rating = Float.valueOf(node.getAttributes().getNamedItem("voteAvg").getNodeValue()); String userVote = node.getAttributes().getNamedItem("voteUser").getNodeValue(); ratingData.Vote = (userVote == "") ? 0 : Float.valueOf(userVote); ratingData.Waypoint = node.getAttributes().getNamedItem("waypoint").getNodeValue(); result.add(ratingData); } } catch (Exception e) { String Ex = ""; if (e != null) { if (e != null && e.getMessage() != null) Ex = "Ex = [" + e.getMessage() + "]"; else if (e != null && e.getLocalizedMessage() != null) Ex = "Ex = [" + e.getLocalizedMessage() + "]"; else Ex = "Ex = [" + e.toString() + "]"; } Log.err(log, "GcVote-Error" + Ex); return null; } return result; }
From source file:com.spoiledmilk.ibikecph.util.Util.java
public static String stringFromJsonAssets(Context context, String path) { String bufferString = ""; try {/*from w ww . j a va 2s. c om*/ InputStream is = context.getAssets().open(path); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); bufferString = new String(buffer); } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } return bufferString; }
From source file:com.oracle.pgbu.common.testcase.CommonBaseTestCase.java
/** * Close all instance of browsers and Webdriver Process on Remote Machine (Selenium Node in Selenium Grid) * /*w w w . j a va 2 s . c om*/ */ public static void killBrowserAndWebDriverProcessOnRemoteNode(String nodeName, String nodeUserName, String nodePassword) { try { String os = System.getProperty("os.name"); if (os.contains("Windows")) { logger.info("About to clean browsers - kill any existing browsers on Remote Node " + nodeName); Runtime.getRuntime().exec("taskkill /s " + nodeName + " /u " + nodeUserName + " /p " + nodePassword + " /F /IM iexplore.exe"); Runtime.getRuntime().exec("taskkill /s " + nodeName + " /u " + nodeUserName + " /p " + nodePassword + " /F /IM chrome.exe"); Runtime.getRuntime().exec("taskkill /s " + nodeName + " /u " + nodeUserName + " /p " + nodePassword + " /F /IM firefox.exe"); Runtime.getRuntime().exec("taskkill /s " + nodeName + " /u " + nodeUserName + " /p " + nodePassword + " /F /IM safari.exe"); logger.info( "About to clean WebDriver process - kill any existing IEDriverServer.exe process on Remote Node " + nodeName); Runtime.getRuntime().exec("taskkill /s " + nodeName + " /u " + nodeUserName + " /p " + nodePassword + " /F /IM IEDriverServer.exe"); } } catch (Exception e) { logger.info("Exception occured while deleting open browser tasks " + e.getLocalizedMessage()); } }
From source file:com.panet.imeta.job.entry.validator.JobEntryValidatorUtils.java
public static void addExceptionRemark(CheckResultSourceInterface source, String propertyName, String validatorName, List<CheckResultInterface> remarks, Exception e) { String key = "messages.failed.unableToValidate"; //$NON-NLS-1$ remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, ValidatorMessages.getString(key, propertyName, e.getClass().getSimpleName() + ": " + e.getLocalizedMessage()), source)); //$NON-NLS-1$ }
From source file:eu.medsea.util.EncodingGuesser.java
/** * Get a Collection of all the possible encodings this byte array could be used to represent. * @param data//from w w w. ja v a2s . c o m * @return the Collection of possible encodings from the supported encodings */ public static Collection getPossibleEncodings(byte[] data) { Collection possibleEncodings = new TreeSet(); if (data == null || data.length == 0) { return possibleEncodings; } // We may have to take account of a BOM (Byte Order Mark) as this could be present at the beginning of // the source byte array. These sequences may match valid bytes at the beginning of binary data but this shouldn't // match any encodings anyway. String encoding = null; for (Iterator it = supportedEncodings.iterator(); it.hasNext();) { // This will eliminate encodings it can't possibly be from the supported encodings // by converting the source byte array to a String using each encoding in turn and // then getting the resultant byte array and checking it against the passed in data. try { // One problem to overcome is that the passed in data may be terminated by an // incomplete character for the current encoding so we need to remove the last character // then get the resulting bytes and only match this against the source byte array. encoding = (String) it.next(); // Check if this encoding has a known bom and if so does it match the beginning of the data array ? // returns either 0 or the length of the bom int lengthBOM = getLengthBOM(encoding, data); // Don't use the BOM when constructing the String String test = new String(getByteArraySubArray(data, lengthBOM, data.length - lengthBOM), encoding); // Only remove the last character if the String is more than 1 character long if (test.length() > 1) { // Remove last character from the test string. test = test.substring(0, test.length() - 2); } // This is the byte array we will compare with the passed in source array copy byte[] compare = null; try { compare = test.getBytes(encoding); } catch (UnsupportedOperationException ignore) { continue; } // Check if source and destination byte arrays are equal if (!compareByteArrays(data, lengthBOM, compare, 0, compare.length)) { // dosn't match so ignore this encoding as it is unlikely to be correct // even if it does contain valid text data. continue; } // If we get this far and the lengthBOM is not 0 then we have a match for this encoding. if (lengthBOM != 0) { // We know we have a perfect match for this encoding so ditch the rest and return just this one possibleEncodings.clear(); possibleEncodings.add(encoding); return possibleEncodings; } // This is a possible match. possibleEncodings.add(encoding); } catch (UnsupportedEncodingException uee) { log.error("The encoding [" + encoding + "] is not supported by your JVM."); } catch (Exception e) { // Log the error but carry on with the next encoding log.error(e.getLocalizedMessage(), e); } } return possibleEncodings; }