List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
From source file:SendMail.java
public static void main(String[] args) { try {/* ww w. j a v a 2 s . com*/ // If the user specified a mailhost, tell the system about it. if (args.length >= 1) System.getProperties().put("mail.host", args[0]); // A Reader stream to read from the console BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // Ask the user for the from, to, and subject lines System.out.print("From: "); String from = in.readLine(); System.out.print("To: "); String to = in.readLine(); System.out.print("Subject: "); String subject = in.readLine(); // Establish a network connection for sending mail URL u = new URL("mailto:" + to); // Create a mailto: URL URLConnection c = u.openConnection(); // Create its URLConnection c.setDoInput(false); // Specify no input from it c.setDoOutput(true); // Specify we'll do output System.out.println("Connecting..."); // Tell the user System.out.flush(); // Tell them right now c.connect(); // Connect to mail host PrintWriter out = // Get output stream to host new PrintWriter(new OutputStreamWriter(c.getOutputStream())); // We're talking to the SMTP server now. // Write out mail headers. Don't let users fake the From address out.print("From: \"" + from + "\" <" + System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getHostName() + ">\r\n"); out.print("To: " + to + "\r\n"); out.print("Subject: " + subject + "\r\n"); out.print("\r\n"); // blank line to end the list of headers // Now ask the user to enter the body of the message System.out.println("Enter the message. " + "End with a '.' on a line by itself."); // Read message line by line and send it out. String line; for (;;) { line = in.readLine(); if ((line == null) || line.equals(".")) break; out.print(line + "\r\n"); } // Close (and flush) the stream to terminate the message out.close(); // Tell the user it was successfully sent. System.out.println("Message sent."); } catch (Exception e) { // Handle any exceptions, print error message. System.err.println(e); System.err.println("Usage: java SendMail [<mailhost>]"); } }
From source file:com.cliqset.magicsig.util.KeyTester.java
public static void main(String[] args) { try {/*from www . ja va2 s .c o m*/ FileInputStream fis = new FileInputStream(keyFile); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); String line = null; while ((line = reader.readLine()) != null) { MagicKey key = new MagicKey(line.getBytes("ASCII")); RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm(); byte[] sig = alg.sign(data, key); System.out.println(Base64.encodeBase64URLSafeString(sig)); boolean verified = alg.verify(data, sig, key); if (!verified) { System.out.println("FAILED - " + line); } //System.out.println(lineSplit[0] + " " + key.toString(true)); } } catch (Exception e) { e.printStackTrace(); } System.out.println("Done."); }
From source file:MainClass.java
public static void main(String[] args) { try {/* w w w .j a va 2 s .c o m*/ URL url = new URL("http://www.java2s.com/"); URLConnection urlConnection = url.openConnection(); Map<String, List<String>> headers = urlConnection.getHeaderFields(); Set<Map.Entry<String, List<String>>> entrySet = headers.entrySet(); for (Map.Entry<String, List<String>> entry : entrySet) { String headerName = entry.getKey(); System.out.println("Header Name:" + headerName); List<String> headerValues = entry.getValue(); for (String value : headerValues) { System.out.print("Header value:" + value); } System.out.println(); System.out.println(); } InputStream inputStream = urlConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line = bufferedReader.readLine(); while (line != null) { System.out.println(line); line = bufferedReader.readLine(); } bufferedReader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ExecDemoPartial.java
public static void main(String argv[]) throws IOException { BufferedReader is; // reader for output of process String line;//from w ww . j ava 2 s. c o m final Process p = Runtime.getRuntime().exec(PROGRAM); Thread waiter = new Thread() { public void run() { try { p.waitFor(); } catch (InterruptedException ex) { // OK, just quit this thread. return; } System.out.println("Program terminated!"); done = true; } }; waiter.start(); // getInputStream gives an Input stream connected to // the process p's standard output (and vice versa). We use // that to construct a BufferedReader so we can readLine() it. is = new BufferedReader(new InputStreamReader(p.getInputStream())); while (!done && ((line = is.readLine()) != null)) System.out.println(line); return; }
From source file:postenergy.PostHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://iplant.dk/addData.php?n=mindass"); try {//from w ww . j av a 2 s. com List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("?n", "=mindass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Input:")) { String key = line.substring(6); // do something with the key System.out.println("key:" + key); } } } catch (IOException e) { System.out.println("There was an error: " + e); } }
From source file:spatialluceneindexer.Main.java
/** * @param args the command line arguments *///from w w w . ja v a2 s . com public static void main(String[] args) { System.out.println("Starting to create the index"); //Open the file of JSON for reading FileOpener fOpener = new FileOpener("parks.json"); //Create the object for writing LuceneWriter luceneWriter = new LuceneWriter("indexDir"); //This is from Jackson which allows for binding the JSON to the Park.java class ObjectMapper objectMapper = new ObjectMapper(); try { //first see if we can open a directory for writing if (luceneWriter.openIndex()) { //get a buffered reader handle to the file BufferedReader breader = new BufferedReader(fOpener.getFileForReading()); String value = null; //loop through the file line by line and parse while ((value = breader.readLine()) != null) { Park park = objectMapper.readValue(value, Park.class); //now submit each park to the lucene writer to add to the index luceneWriter.addPark(park); } } else { System.out.println("We had a problem opening the directory for writing"); } } catch (Exception e) { System.out.println("Threw exception " + e.getClass() + " :: " + e.getMessage()); } finally { luceneWriter.finish(); } System.out.println("Finished created the index"); }
From source file:com.termmed.sampling.ConceptsWithMoreThanThreeRoleGroups.java
/** * The main method./*from w w w. j a v a 2s .co m*/ * * @param args the arguments * @throws Exception the exception */ public static void main(String[] args) throws Exception { System.out.println("Starting..."); Map<String, Set<String>> groupsMap = new HashMap<String, Set<String>>(); File relsFile = new File( "/Users/alo/Downloads/SnomedCT_RF2Release_INT_20160131-1/Snapshot/Terminology/sct2_Relationship_Snapshot_INT_20160131.txt"); BufferedReader br2 = new BufferedReader(new FileReader(relsFile)); String line2; int count2 = 0; while ((line2 = br2.readLine()) != null) { // process the line. count2++; if (count2 % 10000 == 0) { //System.out.println(count2); } List<String> columns = Arrays.asList(line2.split("\t", -1)); if (columns.size() >= 6) { if (columns.get(2).equals("1") && !columns.get(6).equals("0")) { if (!groupsMap.containsKey(columns.get(4))) { groupsMap.put(columns.get(4), new HashSet<String>()); } groupsMap.get(columns.get(4)).add(columns.get(6)); } } } System.out.println("Relationship groups loaded"); Gson gson = new Gson(); System.out.println("Reading JSON 1"); File crossoverFile1 = new File("/Users/alo/Downloads/crossover_role_to_group.json"); String contents = FileUtils.readFileToString(crossoverFile1, "utf-8"); Type collectionType = new TypeToken<Collection<ControlResultLine>>() { }.getType(); List<ControlResultLine> lineObject = gson.fromJson(contents, collectionType); Set<String> crossovers1 = new HashSet<String>(); for (ControlResultLine loopResult : lineObject) { crossovers1.add(loopResult.conceptId); } System.out.println("Crossovers 1 loaded, " + lineObject.size() + " Objects"); System.out.println("Reading JSON 2"); File crossoverFile2 = new File("/Users/alo/Downloads/crossover_group_to_group.json"); String contents2 = FileUtils.readFileToString(crossoverFile2, "utf-8"); List<ControlResultLine> lineObject2 = gson.fromJson(contents2, collectionType); Set<String> crossovers2 = new HashSet<String>(); for (ControlResultLine loopResult : lineObject2) { crossovers2.add(loopResult.conceptId); } System.out.println("Crossovers 2 loaded, " + lineObject2.size() + " Objects"); Set<String> foundConcepts = new HashSet<String>(); int count3 = 0; BufferedWriter writer = new BufferedWriter( new FileWriter(new File("ConceptsWithMoreThanThreeRoleGroups.csv"))); ; for (String loopConcept : groupsMap.keySet()) { if (groupsMap.get(loopConcept).size() > 3) { writer.write(loopConcept); writer.newLine(); foundConcepts.add(loopConcept); count3++; } } writer.close(); System.out.println("Found " + foundConcepts.size() + " concepts"); int countCrossover1 = 0; for (String loopConcept : foundConcepts) { if (crossovers1.contains(loopConcept)) { countCrossover1++; } } System.out.println(countCrossover1 + " are present in crossover_role_to_group"); int countCrossover2 = 0; for (String loopConcept : foundConcepts) { if (crossovers2.contains(loopConcept)) { countCrossover2++; } } System.out.println(countCrossover2 + " are present in crossover_group_to_group"); System.out.println("Done"); }
From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java
public static void main(String[] args) { try {//from w ww. j ava2 s .c o m final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); final String name = in.readLine(); final List<RecordEntry> entries = new LinkedList<RecordEntry>(); String line; while ((line = in.readLine()) != null) { final String[] parts = line.split("\\s+"); final int length = Integer.parseInt(parts[0]); final int start = Integer.parseInt(parts[1]); final String entryName = parts[2]; entries.add(new RecordEntry(length, start, entryName)); } (new RecordClassMaker(name, entries)).execute(); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }
From source file:com.ccc.nhr.test1.NhrSocket.java
public static void main(String args[]) throws IOException, SQLException, ClassNotFoundException { final String host = "192.168.16.146"; final int portNumber = 10010; System.out.println("Creating socket to '" + host + "' on port " + portNumber); Socket socket = new Socket(host, portNumber); final NhrDataService nhrConnection = new NhrConnectionBuilder(socket) .withInputBufferedReader(new BufferedReader(new InputStreamReader(socket.getInputStream()))) .withDataInputStream(new DataInputStream(socket.getInputStream())) .withDataOutputStream(new DataOutputStream(socket.getOutputStream())).build(); ReceiverThread receiverThread = new ReceiverThread(); receiverThread.setNhrConnection(nhrConnection); receiverThread.start();//from w w w.java 2 s . c o m SenderThread senderThread = new SenderThread(); senderThread.setNhrConnection(nhrConnection); senderThread.start(); }
From source file:luceneindexer.Main.java
/** * @param args the command line arguments *///from w ww .ja v a2 s .c o m public static void main(String[] args) { // TODO code application logic here System.out.println("Hello world"); //Open the file of JSON for reading FileOpener fOpener = new FileOpener("parks.json"); //Create the object for writing LuceneWriter luceneWriter = new LuceneWriter("indexDir"); //This is from Jackson which allows for binding the JSON to the Park.java class ObjectMapper objectMapper = new ObjectMapper(); try { //first see if we can open a directory for writing if (luceneWriter.openIndex()) { //get a buffered reader handle to the file BufferedReader breader = new BufferedReader(fOpener.getFileForReading()); String value = null; //loop through the file line by line and parse while ((value = breader.readLine()) != null) { Park park = objectMapper.readValue(value, Park.class); //now submit each park to the lucene writer to add to the index luceneWriter.addPark(park); } } else { System.out.println("We had a problem opening the directory for writing"); } } catch (Exception e) { System.out.println("Threw exception " + e.getClass() + " :: " + e.getMessage()); } finally { //close out the index and release the lock on the file luceneWriter.finish(); } }