List of usage examples for java.io IOException getStackTrace
public StackTraceElement[] getStackTrace()
From source file:akori.Impact.java
static public void main(String[] args) throws IOException { String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\"; String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\"; for (int i = 1; i <= 32; ++i) { for (int k = 1; k <= 15; ++k) { System.out.println("Matrix " + i + "-" + k); BufferedImage img = null; try { img = ImageIO.read(new File(PATHIMG + i + ".png")); } catch (IOException ex) { ex.getStackTrace(); }/*from ww w .ja v a 2s.c o m*/ int ymax = img.getHeight(); int xmax = img.getWidth(); double[][] imagen = new double[ymax][xmax]; BufferedReader in = null; try { in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt")); } catch (FileNotFoundException ex) { ex.getStackTrace(); } String linea; ArrayList<String> lista = new ArrayList<String>(); HashMap<String, String> lista1 = new HashMap<String, String>(); try { for (int j = 0; (linea = in.readLine()) != null; ++j) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[1]); int y = (int) Double.parseDouble(datos[2]); if (x >= xmax || y >= ymax || x <= 0 || y <= 0) { continue; } lista.add(x + "," + y); } } catch (Exception ex) { ex.getStackTrace(); } try { in.close(); } catch (IOException ex) { ex.getStackTrace(); } Iterator iter = lista.iterator(); int[][] matrix = new int[lista.size()][2]; for (int j = 0; iter.hasNext(); ++j) { String xy = (String) iter.next(); String[] datos = xy.split(","); matrix[j][0] = Integer.parseInt(datos[0]); matrix[j][1] = Integer.parseInt(datos[1]); } for (int j = 0; j < matrix.length; ++j) { int std = 50; int x = matrix[j][0]; int y = matrix[j][1]; imagen[y][x] += 1; double aux; normalMatrix(imagen, y, x, std); } FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt"); BufferedWriter bw = new BufferedWriter(fw); for (int j = 0; j < imagen.length; ++j) { for (int t = 0; t < imagen[j].length; ++t) { if (t + 1 == imagen[j].length) bw.write(imagen[j][t] + ""); else bw.write(imagen[j][t] + ","); } bw.write("\n"); } bw.close(); } } }
From source file:org.berkholz.vcard2fritzXML.Main.java
/** * @param args//w ww . ja va 2 s . c o m * @throws IOException * @throws JAXBException * @throws ParseException * */ public static void main(String[] args) throws IOException, JAXBException, ParseException { // Variables for command option parsing List<VCard> vcard = null; // create Options object including file and directory name CommandOptions cmdOptions = new CommandOptions(args); // define the possible command line options cmdOptions.setOptions(); // check if all options meet our requirements cmdOptions.checkOptions(); // create the phonebooks element, contains a phonebook element Phonebooks pbs = new Phonebooks(); // create the phonebook element, will contain all of our contacts, and // assign it to our phonebooks element Phonebook pb = new Phonebook(cmdOptions.phonebookName, 1); pbs.setPhonebooks(pb); // check if vcard input is given via stdin if (!"-".equals(cmdOptions.vcardFile)) { // Read in a vCards try { File file = new File(cmdOptions.vcardFile); // get all vcard entries from file vcard = Ezvcard.parse(file).all(); } catch (IOException e) { System.out.println( "Error while opening file: " + cmdOptions.vcardFile + " StackTrace:\n" + e.getStackTrace()); } } else { try { InputStreamReader inStreamReader = new InputStreamReader(System.in); // get all vcard entries from stdin vcard = Ezvcard.parse(inStreamReader).all(); } catch (IOException ioe) { System.out.println("Error while opening the InputStreamReader" + ioe.getLocalizedMessage()); } } // iterate of any vcard entries Iterator<VCard> vcardIterator = vcard.iterator(); // initialize the uid counter for contacts int uidCounter = 1; while (vcardIterator.hasNext()) { // get next vcard entry VCard vcardElement = vcardIterator.next(); // create new contact to represent the actual vcard element Contact c1 = new Contact(); String tmpmail = new String(); if (vcardElement.getEmails().isEmpty()) { tmpmail = ""; } else { tmpmail = vcardElement.getEmails().get(0).getValue(); } c1.setServices(tmpmail); // TODO: nach mehreren Begriffen suchen, wie cell, mobile etc. Telephony tp = new Telephony(Main.getTelephoneNumberByType(vcardElement.getTelephoneNumbers(), "home"), Main.getTelephoneNumberByType(vcardElement.getTelephoneNumbers(), "work"), Main.getTelephoneNumberByType(vcardElement.getTelephoneNumbers(), "cell")); c1.setTelephony(tp); // skip contact with no mail address and telephone numbers if // command line option -s is given if (cmdOptions.skipEmptyContacts && tp.isEmpty() && c1.getServices().getEmail().isEmpty()) { System.out.println("Skipping: " + vcardElement.getFormattedName().getValue()); continue; } Person p = new Person(); p.setRealName(vcardElement.getStructuredName().getGiven(), vcardElement.getStructuredName().getFamily(), cmdOptions.reversedOrder); c1.setPerson(p); c1.setMod_time(); c1.setUid(uidCounter++); // add contact to out phonebook element pb.addContact(c1); c1 = null; } JAXBContext context = JAXBContext.newInstance(Phonebooks.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // output should be directed to stdout or file if Option -o is given if (cmdOptions.outputFile.isEmpty()) { m.marshal(pbs, System.out); } else { m.marshal(pbs, new File(cmdOptions.outputFile)); } }
From source file:vmwareConDiag.Starter.java
/** * Main method to test if connection to a vCenter can established. It loads also a config.properties with * user credentials for vCenter to establish the connection using the ViJavaConnectionTest. * After established connection some "about information" from the vCenter are received and the connection * will be closed.//from w w w.ja v a 2s . c om * * @param args - No args evaluated */ public static void main(String[] args) { // Init vCenter credentials String host = EMPTY_STRING; String user = EMPTY_STRING; String pass = EMPTY_STRING; Boolean metrics = true; // Used for read in config.properties Properties properties = new Properties(); // vCenter service instance used if a vCenter connection could be established ServiceInstance serviceInstance; // Load config.properties from current directory try { properties.load(new FileInputStream(CONFIG_PROPERTIES)); host = properties.getProperty(PROP_HOST); user = properties.getProperty(PROP_USER); pass = properties.getProperty(PROP_PASS); metrics = Boolean.valueOf(properties.getProperty(PROP_QUERY_METRICS, "true")); doMetrics = metrics; } catch (IOException e) { logger.error("Couldn't read configuration property ['{}']. Error message: '{}'", CONFIG_PROPERTIES, e.getMessage()); logger.debug("Stack trace: '{}'", CONFIG_PROPERTIES, e.getMessage(), e.getStackTrace()); // No vCenter credentials --> Error exit System.exit(1); } // Could read config.properties. System.out.println("Reading virtual machines and ESX hosts from " + host + " with " + user + "/pass(SHA-256) " + DigestUtils.sha256Hex(pass) + "\n"); // Initialize connection with vCenter credentials ViJavaConnectTest viJavaConnectTest = new ViJavaConnectTest(host, user, pass); // Try to establish the connection to vCenter try { System.out.print("Try to connect VMware vCenter " + host + " ... "); // Establish connection serviceInstance = viJavaConnectTest.connect(); // Give some information to test if connection and credentials work System.out.println("SUCCESS\n"); System.out.println("VMware API Type: " + serviceInstance.getAboutInfo().apiType); System.out.println("VMware API Version: " + serviceInstance.getAboutInfo().apiVersion + " build " + serviceInstance.getAboutInfo().build); System.out.println("VMware operating system: " + serviceInstance.getAboutInfo().getOsType() + "\n"); // Give some information about VMware systems System.out.println("Collect Host Systems"); System.out.println("-----------------------"); iterateVmwareHostSystems(serviceInstance); System.out.println("\nCollect Virtual Machines"); System.out.println("------------------------"); iterateVmwareVirtualMachines(serviceInstance); } catch (MalformedURLException e) { logger.error("Malformed URL exception occurred. Error message: '{}'", e.getMessage()); logger.debug("Stack trace: '{}'", e.getStackTrace()); // Connection not possible --> Error exit System.exit(1); } catch (RemoteException e) { logger.error("Remote exception {} occurred. Error message: '{}'", e.getClass().getName(), e.getMessage()); logger.debug("Stack trace: '{}'", e.getStackTrace()); // Connection not possible --> Error exit System.exit(1); } // Disconnect vCenter connection viJavaConnectTest.disconnect(); }
From source file:ProductionJS.java
/** * @param args/* w ww . j a va 2s . c o m*/ */ public static void main(String[] args) { boolean precondition = true; BackupLog backupLog = new BackupLog("log/backupLog.txt"); Property properties = null; Settings settings = null; // Load main cfg file try { properties = new Property("cfg/cfg"); } catch (IOException e) { backupLog.log("ERROR : Config file not found"); precondition = false; } // Load cfg for Log4J if (precondition) { try { DOMConfigurator.configureAndWatch(properties.getProperty("loggerConfiguration")); logger.info("ProductionJS is launched\n_______________________"); } catch (Exception e) { backupLog.log(e.getMessage()); precondition = false; } } // Load settings for current execution if (precondition) { try { settings = new Settings(new File(properties.getProperty("importConfiguration"))); } catch (IOException e) { logger.error("Properties file not found"); precondition = false; } catch (org.json.simple.parser.ParseException e) { logger.error("Properties file reading error : JSON may be invalid, check it!"); precondition = false; } } // All is OK : GO! if (precondition) { logger.info("Configuration OK"); logger.info("\"_______________________\nConcat BEGIN\n_______________________\n"); Concat concat = new Concat(); try { if (settings.getPrior() != null) { logger.info("Add Prior files\n_______________________\n"); concat.addJSONArray(settings.getPrior()); } for (int i = 0; i < settings.getIn().size(); i++) { ProductionJS.logger.info("Importation number " + (i + 1)); ProductionJS.logger.info("Directory imported " + settings.getIn().get(i)); Directory dir = new Directory(new File(settings.getIn().get(i).toString())); dir.scan(); concat.add(dir.getFiles()); } concat.output(settings.getOut()); logger.info("\"_______________________\nConcat END\n_______________________\n"); if (settings.getMinify() != null && settings.getMinify() == true) { logger.info( "\"_______________________\nMinify of concatened file BEGIN\n_______________________\n"); new Minify(new File(settings.getOut()), settings.getOut()); logger.info( "\"_______________________\nMinify of concatened file END\n_______________________\n"); } if (settings.getLicense() != null) { logger.info("Add License\n_______________________\n"); concat = new Concat(); UUID uniqueID = UUID.randomUUID(); PrintWriter tmp = new PrintWriter(uniqueID.toString() + ".txt"); tmp.println(settings.getLicense()); tmp.close(); File license = new File(uniqueID.toString() + ".txt"); concat.add(license); File out = new File(settings.getOut()); File tmpOut = new File(uniqueID + out.getName()); out.renameTo(tmpOut); concat.add(tmpOut); concat.output(settings.getOut()); license.delete(); tmpOut.delete(); } } catch (IOException e) { StackTrace stackTrace = new StackTrace(e.getStackTrace()); logger.error("An error occurred " + e.getMessage() + " " + stackTrace.toString()); } } }
From source file:Main.java
public static String readString(File file) { StringBuilder builder = new StringBuilder(); if (!file.exists()) { System.err.println("Can't Find " + file); }/*from www. j a v a 2 s .c om*/ try { BufferedReader in = new BufferedReader(new FileReader(file)); String str; while ((str = in.readLine()) != null) { //System.out.println(str); builder.append(str); } in.close(); } catch (IOException e) { e.getStackTrace(); } return builder.toString(); }
From source file:Main.java
/** * Read Access token from Json object that we got from O8 Auth server. * //from w w w . j ava 2 s . co m */ private static String getAccessToken(JsonReader reader) throws IOException { String text = null; try { reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("access_token")) { text = reader.nextString(); break; } } //reader.endObject(); } catch (IOException ex) { Log.e(TAG, ex.getStackTrace().toString()); } return text; }
From source file:Main.java
public static void killProcess(String packageName) { String processId = ""; try {//from www.jav a2s .com Runtime r = Runtime.getRuntime(); Process p = r.exec("ps"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String inline; while ((inline = br.readLine()) != null) { if (packageName != null) { if (inline.contains(packageName)) { break; } } else { Log.e("PvTorrent_proc", "packageName is null"); } } br.close(); Log.i("PvTorrent_proc", "inline" + inline); if (inline != null) { StringTokenizer processInfoTokenizer = new StringTokenizer(inline); int count = 0; while (processInfoTokenizer.hasMoreTokens()) { count++; processId = processInfoTokenizer.nextToken(); if (count == 2) { break; } } Log.i("PvTorrent_proc", "kill process : " + processId); r.exec("kill -9 " + processId); } } catch (IOException ex) { Log.e("PvTorrent_proc", "kill" + ex.getStackTrace()); } }
From source file:org.berkholz.vcard2fritzXML.Main.java
/** * Prints out the vcardfile to stdout.//from www .j a va 2 s . co m * * @param fis VCard file as FileInputStream. */ public static void printVCardFile(FileInputStream fis) { int oneByte; try { while ((oneByte = fis.read()) != -1) { System.out.write(oneByte); // System.out.print((char)oneByte); // could also do this } fis.close(); } catch (IOException e) { System.out.println("Error while printing the vcard file:\nStackTrace:\n" + e.getStackTrace()); } System.out.flush(); System.out.println(); }
From source file:com.bah.applefox.main.plugins.pageranking.utilities.PRtoFile.java
public static boolean writeToFile(String[] args) { String fileName = args[16];/* w ww .j a va2 s. c o m*/ File f = new File(fileName); try { f.createNewFile(); OutputStream file = new FileOutputStream(f); OutputStream buffer = new BufferedOutputStream(file); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(createMap(args)); out.flush(); out.close(); } catch (IOException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } catch (AccumuloException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } catch (AccumuloSecurityException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } catch (TableNotFoundException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } return true; }
From source file:com.catalyst.sonar.score.batch.util.FileInstaller.java
/** * Checks if a directory exists; if it doesn't, it attempts to create one. * //from w ww . j a v a 2 s . co m * @param directory * @return true if the directory exists or was successfully created, false * otherwise. */ private static boolean ensureDirectoryExists(final File directory) { logger.debug("ensureDirectoryExists)"); logger.debug("Name = " + directory.getName()); logger.debug("AbsolutePath = " + directory.getAbsolutePath()); try { logger.debug("CanonicalPath = " + directory.getCanonicalPath()); } catch (IOException e) { logger.debug(e.getStackTrace().toString()); } boolean success = directory.exists() || directory.mkdir(); logger.debug("returning " + success); return success; }