List of usage examples for java.lang Exception toString
public String toString()
From source file:gephi.spade.panel.fcsFile.java
/** * main ---//from w w w .ja v a 2 s .c om * <p> * A main method to test the class. * </p> * * @param args * <code>String</code> array of arguments at the command prompt. */ public static void main(String[] args) { if (args.length <= 0) { // If there are no arguments, then exit. System.out.println("Usage:"); System.out.println("---"); System.out.println(">java fcsFile <path to FCS file>"); System.exit(0); } try { // Echo the file we are checking System.out.println("Checking \"" + args[0] + "\" ..."); fcsFile f; // Read in the file if (args.length > 1) { // If there are more than one argument, then extract the events. f = new fcsFile(args[0], true); } else { // Otherwise, don't extract the events. f = new fcsFile(args[0], false); } // Test whether the file is an FCS file if (f.isFCS()) { // If the file is an FCS file, then print out the file is an FCS // file. System.out.println("\"" + args[0] + "\" is an FCS file."); // Print out the information if the file is an FCS file printFCSFile(f); } else { // Otherwise, print out the file is not an FCS file. System.out.println("\"" + args[0] + "\" is not an FCS file."); } /* * // Print out whether the file is an FCS file using the static * method if(isFCSFile(f.getFile())) { // If the file is an FCS * file, then print out the file is an FCS file. * System.out.println("\"" + args[0] + "\" is an FCS file."); } else * { // Otherwise, print out the file is not an FCS file. * System.out.println("\"" + args[0] + "\" is not an FCS file."); } */ } catch (Exception e) { // Print out any exceptions System.err.println(e.toString()); } }
From source file:ReadTemp.java
/** * Method main//w w w. ja va 2 s .co m * * * @param args * * @throws OneWireException * @throws OneWireIOException * */ public static void main(String[] args) throws OneWireIOException, OneWireException { boolean usedefault = false; DSPortAdapter access = null; String adapter_name = null; String port_name = null; variableNames = new HashMap(); if ((args == null) || (args.length < 1)) { try { access = OneWireAccessProvider.getDefaultAdapter(); if (access == null) throw new Exception(); } catch (Exception e) { System.out.println("Couldn't get default adapter!"); printUsageString(); return; } usedefault = true; } if (!usedefault) { StringTokenizer st = new StringTokenizer(args[0], "_"); if (st.countTokens() != 2) { printUsageString(); return; } adapter_name = st.nextToken(); port_name = st.nextToken(); System.out.println("Adapter Name: " + adapter_name); System.out.println("Port Name: " + port_name); } if (access == null) { try { access = OneWireAccessProvider.getAdapter(adapter_name, port_name); } catch (Exception e) { System.out.println("That is not a valid adapter/port combination."); Enumeration en = OneWireAccessProvider.enumerateAllAdapters(); while (en.hasMoreElements()) { DSPortAdapter temp = (DSPortAdapter) en.nextElement(); System.out.println("Adapter: " + temp.getAdapterName()); Enumeration f = temp.getPortNames(); while (f.hasMoreElements()) { System.out.println(" Port name : " + ((String) f.nextElement())); } } return; } } boolean scan = false; if (args.length > 1) { if (args[1].compareTo("--scan") == 0) scan = true; } else { populateVariableNames(); } while (true) { access.adapterDetected(); access.targetAllFamilies(); access.beginExclusive(true); access.reset(); access.setSearchAllDevices(); boolean next = access.findFirstDevice(); if (!next) { System.out.println("Could not find any iButtons!"); return; } while (next) { OneWireContainer owc = access.getDeviceContainer(); boolean isTempContainer = false; TemperatureContainer tc = null; try { tc = (TemperatureContainer) owc; isTempContainer = true; } catch (Exception e) { tc = null; isTempContainer = false; //just to reiterate } if (isTempContainer) { String id = owc.getAddressAsString(); if (scan) { System.out.println("= Temperature Sensor Found: " + id); } else { double high = 0.0; double low = 0.0; byte[] state = tc.readDevice(); boolean selectable = tc.hasSelectableTemperatureResolution(); if (selectable) try { tc.setTemperatureResolution(0.0625, state); } catch (Exception e) { System.out.println("= Could not set resolution for " + id + ": " + e.toString()); } try { tc.writeDevice(state); } catch (Exception e) { System.out.println("= Could not write device state, all changes lost."); System.out.println("= Exception occurred for " + id + ": " + e.toString()); } boolean conversion = false; try { tc.doTemperatureConvert(state); conversion = true; } catch (Exception e) { System.out.println("= Could not complete temperature conversion..."); System.out.println("= Exception occurred for " + id + ": " + e.toString()); } if (conversion) { state = tc.readDevice(); double temp = tc.getTemperature(state); if (temp < 84) { double temp_f = (9.0 / 5.0) * temp + 32; setVariable(id, Double.toString(temp_f)); } System.out.println("= Reported temperature from " + (String) variableNames.get(id) + "(" + id + "):" + temp); } } } next = access.findNextDevice(); } if (!scan) { try { Thread.sleep(60 * 5 * 1000); } catch (Exception e) { } } else { System.exit(0); } } }
From source file:Main.java
public static String bytesToString(byte[] bytes) { try {// www. j a v a 2 s .co m return new String(bytes, "ASCII"); } catch (Exception ex) { return ex.toString(); } }
From source file:Cat.java
public static void concatenate(String fileName) { RandomAccessFile file = null; String line = null;//w ww . j av a2 s . c o m try { file = new RandomAccessFile(fileName, "r"); while ((line = file.readLine()) != null) { System.out.println(line); } return; } catch (FileNotFoundException fnf) { System.err.println("File: " + fileName + " not found."); } catch (Exception e) { System.err.println(e.toString()); } finally { if (file != null) { try { file.close(); } catch (IOException io) { } } } }
From source file:Main.java
public static int parseInt(String str) { try {//from www. j ava 2 s. c o m return Integer.parseInt(str != null && !"".equalsIgnoreCase(str) ? str : "0"); } catch (Exception e) { System.out.println(e.toString()); } return 0; }
From source file:Main.java
public static String commandExecutionStatusMessage(String jsonString) { try {/* www .jav a 2 s.c o m*/ JSONObject json = new JSONObject(jsonString); String condition = json.getString("condition"); String message = json.getString("message"); if (message == "null") { if (condition == "true") return "Successful"; else return "Error"; } else { return message; } } catch (Exception e) { return e.toString(); } }
From source file:MainClass.java
public static void createDatabase() { String data = "jdbc:derby:presidents;create=true"; try {//from w ww. j a va2 s . c o m Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection conn = DriverManager.getConnection(data); Statement st = conn.createStatement(); int result = st.executeUpdate("CREATE TABLE contacts (dex INTEGER NOT NULL PRIMARY KEY " + "GENERATED ALWAYS AS identity (START WITH 1, INCREMENT BY 1), " + "name VARCHAR(40), address1 VARCHAR(40), address2 VARCHAR(40))"); result = st.executeUpdate( "INSERT INTO contacts (name, address1, address2" + ") VALUES('J','Center', 1 , 'GA')"); st.close(); } catch (Exception e) { System.out.println("Error - " + e.toString()); } }
From source file:MainClass.java
public static void readDatabase() { String data = "jdbc:derby:presidents"; try {// w w w. j ava2 s .c o m Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection conn = DriverManager.getConnection(data, "", ""); Statement st = conn.createStatement(); ResultSet rec = st.executeQuery("SELECT * FROM contacts ORDER BY name"); while (rec.next()) { System.out.println( rec.getString("name") + "\n" + rec.getString("address1") + "\n" + rec.getString("address2") + "\n" + rec.getString("phone") + "\n" + rec.getString("email") + "\n"); } st.close(); } catch (Exception e) { System.out.println("Error - " + e.toString()); } }
From source file:com.hackathon.gavin.string.parser.MyAccountParser.java
public static JSONArray httpGetCall(String urlString, String jsonArrayName) { JSONArray result = null;/*from w w w. j av a 2 s . co m*/ HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(urlString); try { HttpResponse getResponse = client.execute(request); BufferedReader reader = new BufferedReader( new InputStreamReader(getResponse.getEntity().getContent(), "UTF-8")); StringBuilder builder = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } //result = new JSONObject(builder.toString()).getJSONArray(jsonArrayName); JSONObject obj = new JSONObject(builder.toString()); result = obj.getJSONArray(jsonArrayName); } catch (Exception e) { System.out.println(e.toString()); } return result; }
From source file:pro.jariz.reisplanner.api.NSAPI.java
public static void Error(Exception e) { Log.e("NSAPI", e.toString()); e.printStackTrace(); }