List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:sendfile.java
public static void main(String[] args) { if (args.length != 5) { System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false"); System.exit(1);// w w w .j av a 2s . co m } String to = args[0]; String from = args[1]; String host = args[2]; String filename = args[3]; boolean debug = Boolean.valueOf(args[4]).booleanValue(); String msgText1 = "Sending a file.\n"; String subject = "Sending a file"; // create some properties and get the default Session Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(msgText1); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message mbp2.attachFile(filename); /* * Use the following approach instead of the above line if * you want to control the MIME type of the attached file. * Normally you should never need to do this. * FileDataSource fds = new FileDataSource(filename) { public String getContentType() { return "application/octet-stream"; } }; mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); */ // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // set the Date: header msg.setSentDate(new Date()); /* * If you want to control the Content-Transfer-Encoding * of the attached file, do the following. Normally you * should never need to do this. * msg.saveChanges(); mbp2.setHeader("Content-Transfer-Encoding", "base64"); */ // send the message Transport.send(msg); } catch (MessagingException mex) { mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); } } catch (IOException ioex) { ioex.printStackTrace(); } }
From source file:examples.ntp.SimpleNTPServer.java
public static void main(String[] args) { int port = NtpV3Packet.NTP_PORT; if (args.length != 0) { try {/*from w w w . j av a2s . c o m*/ port = Integer.parseInt(args[0]); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } } SimpleNTPServer timeServer = new SimpleNTPServer(port); try { timeServer.start(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java
public static void main(String[] args) throws ParseException, JsonProcessingException, IOException, URISyntaxException { Options options = new Options(); options.addOption("d", true, "Absolute file path to the directory containing the image files."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("d")) { String imageDirectoryPath = cmd.getOptionValue("d"); Path imageDirectory = Paths.get(imageDirectoryPath); final List<Path> files = new ArrayList<>(); try {//from w ww. j a v a2 s .c om Files.walkFileTree(imageDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory()) { // TODO there must be a more elegant solution for filtering jpeg files... if (file.getFileName().toString().endsWith("jpg")) { files.add(file); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } Collections.sort(files, new Comparator() { @Override public int compare(Object fileOne, Object fileTwo) { String filename1 = ((Path) fileOne).getFileName().toString(); String filename2 = ((Path) fileTwo).getFileName().toString(); try { // numerical sorting Integer number1 = Integer.parseInt(filename1.substring(0, filename1.lastIndexOf("."))); Integer number2 = Integer.parseInt(filename2.substring(0, filename2.lastIndexOf("."))); return number1.compareTo(number2); } catch (NumberFormatException nfe) { // alpha-numerical sorting return filename1.compareToIgnoreCase(filename2); } } }); generateManifest(imageDirectory.getFileName().toString(), files); } else { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ManifestGenerator", options); } }
From source file:net.sf.jsignpdf.verify.SignatureCounter.java
/** * Main program.// www.j a v a 2 s . c o m * * @param args */ public static void main(String[] args) { // create the Options final Option optHelp = new Option("h", "help", false, "print this message"); final Option optDebug = new Option("d", "debug", false, "enables debug output"); final Option optNames = new Option("n", "names", false, "print comma separated signature names instead of the count"); final Option optPasswd = new Option("p", "password", true, "set password for opening PDF"); optPasswd.setArgName("password"); final Options options = new Options(); options.addOption(optHelp); options.addOption(optDebug); options.addOption(optNames); options.addOption(optPasswd); CommandLine line = null; try { // create the command line parser CommandLineParser parser = new PosixParser(); // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Unable to parse command line (Use -h for the help)\n" + exp.getMessage()); System.exit(Constants.EXIT_CODE_PARSE_ERR); } final String[] tmpArgs = line.getArgs(); if (line.hasOption("h") || args == null || args.length == 0) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(70, "java -jar SignatureCounter.jar [file1.pdf [file2.pdf ...]]", "JSignPdf SignatureCounter is a command line tool which prints count of signatures in given PDF document.", options, null, true); } else { byte[] tmpPasswd = null; if (line.hasOption("p")) { tmpPasswd = line.getOptionValue("p").getBytes(); } final boolean debug = line.hasOption("d"); final boolean names = line.hasOption("n"); for (String tmpFilePath : tmpArgs) { if (debug) { System.out.print("Counting signatures in " + tmpFilePath + ": "); } final File tmpFile = new File(tmpFilePath); if (!tmpFile.canRead()) { System.err.println("Couldn't read the file. Check the path and permissions: " + tmpFilePath); System.exit(Constants.EXIT_CODE_CANT_READ_FILE); } try { final PdfReader pdfReader = PdfUtils.getPdfReader(tmpFilePath, tmpPasswd); @SuppressWarnings("unchecked") final List<String> sigNames = pdfReader.getAcroFields().getSignatureNames(); if (names) { //print comma-separated names boolean isNotFirst = false; for (String sig : sigNames) { if (isNotFirst) { System.out.println(","); } else { isNotFirst = true; } System.out.println(sig); } } else { //normal processing print only count of signatures System.out.println(sigNames.size()); if (debug) { System.out.println("Signature names: " + sigNames); } } } catch (IOException e) { e.printStackTrace(); System.exit(Constants.EXIT_CODE_COMMON_ERROR); } } } }
From source file:com.bluexml.tools.miscellaneous.Translate.java
/** * @param args//from w w w . j ava2 s . co m */ public static void main(String[] args) { System.out.println("Translate.main() 1"); Console console = System.console(); System.out.println("give path to folder that contains properties files"); Scanner scanIn = new Scanner(System.in); try { // TODO Auto-generated method stub String sWhatever; System.out.println("Translate.main() 2"); sWhatever = scanIn.nextLine(); System.out.println("Translate.main() 3"); System.out.println(sWhatever); File inDir = new File(sWhatever); FilenameFilter filter = new FilenameFilter() { public boolean accept(File arg0, String arg1) { return arg1.endsWith("properties"); } }; File[] listFiles = inDir.listFiles(filter); for (File file : listFiles) { prapareFileToTranslate(file, inDir); } System.out.println("please translate text files and press enter"); String readLine = scanIn.nextLine(); System.out.println("Translate.main() 4"); for (File file : listFiles) { File values = new File(file.getParentFile(), file.getName() + ".txt"); writeBackValues(values, file); values.delete(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { scanIn.close(); } }
From source file:contractEditor.contractHOST1.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST1"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "France"); serviceDescription.put("certificate", "true"); serviceDescription.put("volume", "100_GB"); serviceDescription.put("price", "6_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_98_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 HashMap host_rule1 = new HashMap(); HashMap VM_rule1 = new HashMap(); host_rule1.put("ID", "HOST1"); VM_rule1.put("purpose", "test"); ArrayList rule1 = new ArrayList(); rule1.add("prohibition"); rule1.add(host_rule1);/*from ww w . j a v a 2s .c om*/ rule1.add(VM_rule1); ArrayList policyInConstraint1 = new ArrayList(); policyInConstraint1.add(rule1); ArrayList creationConstraint1 = new ArrayList(); creationConstraint1.add("other"); creationConstraint1.add("true"); creationConstraint1.add("true"); creationConstraint1.add(policyInConstraint1); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try { FileWriter file = new FileWriter("confSP" + File.separator + "Host1.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
From source file:contractEditor.contractHOST2.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST2"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "UK"); serviceDescription.put("certificate", "false"); serviceDescription.put("volume", "200_GB"); serviceDescription.put("price", "5_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_99_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 HashMap host_rule1 = new HashMap(); HashMap VM_rule1 = new HashMap(); host_rule1.put("ID", "HOST2"); VM_rule1.put("data", "private"); ArrayList rule1 = new ArrayList(); rule1.add("prohibition"); rule1.add(host_rule1);//from w w w . jav a 2 s. co m rule1.add(VM_rule1); ArrayList policyInConstraint1 = new ArrayList(); policyInConstraint1.add(rule1); ArrayList creationConstraint1 = new ArrayList(); creationConstraint1.add("other"); creationConstraint1.add("true"); creationConstraint1.add("true"); creationConstraint1.add(policyInConstraint1); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try { FileWriter file = new FileWriter("confSP" + File.separator + "Host2.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
From source file:contractEditor.contractHOST3.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST3"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "China"); serviceDescription.put("certificate", "false"); serviceDescription.put("volume", "70_GB"); serviceDescription.put("price", "4_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_97_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 HashMap host_rule1 = new HashMap(); HashMap VM_rule1 = new HashMap(); host_rule1.put("ID", "HOST3"); VM_rule1.put("application", "internal"); ArrayList rule1 = new ArrayList(); rule1.add("prohibition"); rule1.add(host_rule1);/*from w ww. j av a 2 s.c o m*/ rule1.add(VM_rule1); ArrayList policyInConstraint1 = new ArrayList(); policyInConstraint1.add(rule1); ArrayList creationConstraint1 = new ArrayList(); creationConstraint1.add("other"); creationConstraint1.add("true"); creationConstraint1.add("true"); creationConstraint1.add(policyInConstraint1); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try { FileWriter file = new FileWriter("confSP" + File.separator + "Host3.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
From source file:PagedSearch.java
public static void main(String[] args) { Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); /* Specify host and port to use for directory service */ env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {/* w ww . java 2s. c o m*/ LdapContext ctx = new InitialLdapContext(env, null); // Activate paged results int pageSize = 5; byte[] cookie = null; ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.NONCRITICAL) }); int total; do { /* perform the search */ NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); /* for each entry print out name + all attrs and values */ while (results != null && results.hasMore()) { SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); } // Examine the paged results control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; total = prrc.getResultSize(); if (total != 0) { System.out.println("***************** END-OF-PAGE " + "(total : " + total + ") *****************\n"); } else { System.out.println( "***************** END-OF-PAGE " + "(total: unknown) ***************\n"); } cookie = prrc.getCookie(); } } } else { System.out.println("No controls were sent from the server"); } // Re-activate paged results ctx.setRequestControls( new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } while (cookie != null); ctx.close(); } catch (NamingException e) { System.err.println("PagedSearch failed."); e.printStackTrace(); } catch (IOException ie) { System.err.println("PagedSearch failed."); ie.printStackTrace(); } }
From source file:com.maya.portAuthority.googleMaps.Instructions.java
public static void main(String[] args) throws Exception { String jsonData = ""; BufferedReader br = null;//from w w w.java2 s . c om try { String line; // To test: Store JSON by striking // https://maps.googleapis.com/maps/api/directions/json?origin=40.4419433,-80.00331349999999&destination=40.44088273536,-80.000846662042&mode=walk&transit_mode=walking&key=AIzaSyBzW19DGDOi_20t46SazRquCLw9UNp_C8s // in a file, and provide file location below: br = new BufferedReader(new FileReader("C:\\Users\\Adithya\\Desktop\\testjson.txt")); while ((line = br.readLine()) != null) { jsonData += line + "\n"; } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } } // System.out.println("File Content: \n" + jsonData); JSONObject obj = new JSONObject(jsonData); System.out.println(Instructions.getInstructions(obj)); System.out.println(Instructions.printWayPoints(obj)); }