List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:com.github.hdl.tensorflow.yarn.app.TFServerLauncher.java
public static void main(String[] args) { LOG.info("start container"); TFServerLauncher server = new TFServerLauncher(); try {/* www .j a va2 s . c o m*/ try { if (!server.init(args)) { LOG.info("init failed!"); } } catch (IOException e) { e.printStackTrace(); } } catch (ParseException e) { LOG.info("parse failed"); e.printStackTrace(); } server.startTFServer(); }
From source file:icevaluation.BingAPIAccess.java
public static void main(String[] args) { String searchText = "arts site:wikipedia.org"; searchText = searchText.replaceAll(" ", "%20"); // String accountKey="jTRIJt9d8DR2QT/Z3BJCAvY1BfoXj0zRYgSZ8deqHHo"; String accountKey = "JfeJSA3x6CtsyVai0+KEP0A6CYEUBT8VWhZmm9CS738"; byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes()); String accountKeyEnc = new String(accountKeyBytes); URL url;//from w w w. ja v a 2 s. c o m try { url = new URL("https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27Web%27&Query=%27" + searchText + "%27&$format=JSON"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Basic " + accountKeyEnc); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String output; System.out.println("Output from Server .... \n"); //write json to string sb int c = 0; if ((output = br.readLine()) != null) { System.out.println("Output is: " + output); sb.append(output); c++; //System.out.println("C:"+c); } conn.disconnect(); //find webtotal among output int find = sb.indexOf("\"WebTotal\":\""); int startindex = find + 12; System.out.println("Find: " + find); int lastindex = sb.indexOf("\",\"WebOffset\""); System.out.println(sb.substring(startindex, lastindex)); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.github.fastjson.MapPractice.java
/** * @param args//w ww .j a va 2 s. c o m */ public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put("name", "doctor"); map.put("age", "1118"); map.put("sex", "man"); String jsonString = JSON.toJSONString(map); System.out.println(jsonString); InputStream resourceAsStream = MapPractice.class.getResourceAsStream("/fastjson/map1.json"); String jString = null; try { jString = IOUtils.toString(resourceAsStream); } catch (IOException e) { e.printStackTrace(); } Map<?, ?> parse = JSON.parseObject(jString, Map.class); System.out.println(parse); for (Object key : parse.keySet()) { System.out.println(key + ":" + parse.get(key)); } InputStream resourceAsStream2 = MapPractice.class.getResourceAsStream("/fastjson/map2.json"); String jString2 = null; try { jString2 = IOUtils.toString(resourceAsStream2); } catch (IOException e) { e.printStackTrace(); } Map<?, ?> parseObject = JSON.parseObject(jString2, Map.class); System.out.println(JSON.toJSON(parseObject)); System.out.println("??"); Object object = parseObject.get("currentKey"); System.out.println("currentKey" + ":" + object); Map<?, ?> object2 = (Map<?, ?>) parseObject.get("keyMap"); for (Object key : object2.keySet()) { System.out.println(key + ":" + object2.get(key)); } }
From source file:gda.util.PackageMaker.java
/** * @param args//from w w w . j av a 2s . co m */ public static void main(String args[]) { String destDir = null; if (args.length == 0) return; String filename = args[0]; if (args.length > 1) destDir = args[1]; try { ClassParser cp = new ClassParser(filename); JavaClass classfile = cp.parse(); String packageName = classfile.getPackageName(); String apackageName = packageName.replace(".", File.separator); if (destDir != null) destDir = destDir + File.separator + apackageName; else destDir = apackageName; File destFile = new File(destDir); File existFile = new File(filename); File parentDir = new File(existFile.getAbsolutePath().substring(0, existFile.getAbsolutePath().lastIndexOf(File.separator))); String allFiles[] = parentDir.list(); Vector<String> selectedFiles = new Vector<String>(); String toMatch = existFile.getName().substring(0, existFile.getName().lastIndexOf(".")); for (int i = 0; i < allFiles.length; i++) { if (allFiles[i].startsWith(toMatch + "$")) selectedFiles.add(allFiles[i]); } FileUtils.copyFileToDirectory(existFile, destFile); Object[] filestoCopy = selectedFiles.toArray(); for (int i = 0; i < filestoCopy.length; i++) { FileUtils.copyFileToDirectory(new File((String) filestoCopy[i]), destFile); } } catch (IOException e) { e.printStackTrace(); } }
From source file:listfiles.ListFiles.java
/** * @param args the command line arguments */// ww w. ja v a 2s .co m public static void main(String[] args) { // TODO code application logic here BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String folderPath = ""; String fileName = "DirectoryFiles.xlsx"; try { System.out.println("Folder path :"); folderPath = reader.readLine(); //System.out.println("Output File Name :"); //fileName = reader.readLine(); XSSFWorkbook wb = new XSSFWorkbook(); FileOutputStream fileOut = new FileOutputStream(folderPath + "\\" + fileName); XSSFSheet sheet1 = wb.createSheet("Files"); int row = 0; Stream<Path> stream = Files.walk(Paths.get(folderPath)); Iterator<Path> pathIt = stream.iterator(); String ext = ""; while (pathIt.hasNext()) { Path filePath = pathIt.next(); Cell cell1 = checkRowCellExists(sheet1, row, 0); Cell cell2 = checkRowCellExists(sheet1, row, 1); row++; ext = FilenameUtils.getExtension(filePath.getFileName().toString()); cell1.setCellValue(filePath.getFileName().toString()); cell2.setCellValue(ext); } sheet1.autoSizeColumn(0); sheet1.autoSizeColumn(1); wb.write(fileOut); fileOut.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("Program Finished"); }
From source file:edu.umass.cs.gnsclient.console.CommandLineInterface.java
/** * Starts the GNS command line interface (CLI) console * * @param args optional argument is -silent for no console output * @throws Exception/*w w w.j a v a2 s . c o m*/ */ public static void main(String[] args) throws Exception { try { CommandLine parser = initializeOptions(args); if (parser.hasOption("help")) { printUsage(); //System.out.println("-host and -port are required!"); System.exit(1); } boolean silent = parser.hasOption("silent"); boolean noDefaults = parser.hasOption("noDefaults"); ConsoleReader consoleReader = new ConsoleReader(System.in, new PrintWriter(System.out, true)); ConsoleModule module = new ConsoleModule(consoleReader); if (noDefaults) { module.setUseGnsDefaults(false); KeyPairUtils.removeDefaultGns(); } module.setSilent(silent); if (!silent) { module.printString("GNS Client Version: " + GNSClientConfig.readBuildVersion() + "\n"); } module.handlePrompt(); System.exit(0); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } }
From source file:examples.nntp.ListNewsgroups.java
public static void main(String[] args) { if (args.length < 1) { System.err.println("Usage: newsgroups newsserver [pattern]"); return;/*from ww w .j av a 2s .c o m*/ } NNTPClient client = new NNTPClient(); String pattern = args.length >= 2 ? args[1] : ""; try { client.connect(args[0]); int j = 0; try { for (String s : client.iterateNewsgroupListing(pattern)) { j++; System.out.println(s); } } catch (IOException e1) { e1.printStackTrace(); } System.out.println(j); j = 0; for (NewsgroupInfo n : client.iterateNewsgroups(pattern)) { j++; System.out.println(n.getNewsgroup()); } System.out.println(j); } catch (IOException e) { e.printStackTrace(); } finally { try { if (client.isConnected()) { client.disconnect(); } } catch (IOException e) { System.err.println("Error disconnecting from server."); e.printStackTrace(); System.exit(1); } } }
From source file:net.iubris.ipc_d3.openhours.CsvToOpenHours.java
public static void main(String[] args) { try {//from w ww . j a v a 2 s. co m // String input = args[0]; String input = "../../data/divertimento_e_ristoro.csv"; String jsonFileAsString = FileUtils.readFile(input, Charset.defaultCharset()); JSONArray adjustedHours = new CsvToOpenHours().adjustHours(jsonFileAsString); String openHoursCSV = new CsvToOpenHours().adjustHoursToCSVWithoutHeader(adjustedHours); FileUtils.writeToFile(openHoursCSV, "divertimento_e_ristoro_-_openhours.csv"); String openHoursJSON = new CsvToOpenHours().adjustHoursToJSONString(adjustedHours); FileUtils.writeToFile(openHoursJSON, "divertimento_e_ristoro_-_openhours.json"); // System.out.println(openHoursCSV); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.cmu.cs.diamond.pathfind.main.PathFindDjango.java
public static void main(String[] args) { if (args.length != 4 && args.length != 5) { System.out.println("usage: " + PathFindDjango.class.getName() + " predicate_dir interface_map slide_map annotation_uri"); return;//ww w . j av a 2 s. co m } final String predicateDir = args[0]; final String interfaceMap = args[1]; final String slideMap = args[2]; final String annotationUri = args[3]; final File slide; if (args.length == 5) { slide = new File(args[4]); } else { slide = null; } final AnnotationStore annotationStore = new DjangoAnnotationStore(new HttpClient(), annotationUri); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { new PathFindFrame(predicateDir, annotationStore, interfaceMap, slideMap, slide, false); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE); } } }); }
From source file:jsonparser.ToJSON.java
public static void main(String args[]) throws FileNotFoundException, IOException { String text_file = "C:/Users/Kevin/Documents/NetBeansProjects/JsonParser/src/jsonparser/sample.txt"; File file = new File(text_file); String s1, s2, s3;/*from w w w.j a va 2s. c o m*/ s1 = (String) FileUtils.readLines(file).get(0); String split1[] = s1.split("="); contact_id = split1[1]; s2 = (String) FileUtils.readLines(file).get(1); String split2[] = s2.split("="); confidence_level = Float.valueOf(split2[1]); s3 = (String) FileUtils.readLines(file).get(2); String split3[] = s3.split("="); if (split3[1].equals(" Found")) { is_matched = true; } else { is_matched = false; } System.out.println("Read from text file:"); System.out.println("contact_id =" + contact_id); System.out.println("confidence_level = " + confidence_level); System.out.println("is_matched = " + is_matched); FacialRecognition fr = new FacialRecognition(); fr.setContactID(contact_id); fr.setConfidenceLevel(confidence_level); fr.setIsMatched(is_matched); Gson gson = new GsonBuilder().setPrettyPrinting().create(); //convert java object to JSON format String json = gson.toJson(fr); //write JSON to a file try { //write converted json data to a file named "CountryGSON.json" FileWriter writer = new FileWriter( "C:/Users/Kevin/Documents/NetBeansProjects/JsonParser/src/jsonparser/test.json", true); writer.write("" + json + ",\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } //eventually need to change to send over back to client-side System.out.println(); System.out.println("Coverting strings into JSON..."); System.out.println(json); }