List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
From source file:web.restful.ClientTest.java
public static void main(String[] args) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/session"); put.setEntity(new StringEntity("upenkwbq"));// session ID client.execute(put);//from ww w.j ava2 s .c o m put.releaseConnection(); put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/bucket"); put.setEntity(new StringEntity("Level1/Level1_Bin_1.txt")); // bucket name client.execute(put); put.releaseConnection(); put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/method"); put.setEntity(new StringEntity("chauvenet")); // method name client.execute(put); put.releaseConnection(); HttpGet get = new HttpGet("http://localhost:8080/ss16-lab-web/resources/outliers"); HttpResponse response = client.execute(get); HttpEntity en = response.getEntity(); InputStreamReader i = new InputStreamReader(en.getContent()); BufferedReader rd = new BufferedReader(i); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } }
From source file:org.keycloak.example.CustomerCli.java
public static void main(String[] args) throws Exception { keycloak = new KeycloakInstalled(); br = new BufferedReader(new InputStreamReader(System.in)); printHelp();/*from w w w. j a v a 2 s .c om*/ printDivider(); System.out.print("$ "); for (String s = br.readLine(); s != null; s = br.readLine()) { printDivider(); try { if (s.equals("login")) { keycloak.login(System.out, br); System.out.println("Logged in: " + keycloak.getToken().getSubject()); } else if (s.equals("logout")) { keycloak.logout(); System.out.println("Logged out"); } else if (s.equals("login-desktop")) { keycloak.loginDesktop(); System.out.println("Logged in: " + keycloak.getToken().getSubject()); } else if (s.equals("login-manual")) { keycloak.loginManual(System.out, br); System.out.println("Logged in: " + keycloak.getToken().getSubject()); } else if (s.equals("profile")) { profile(); } else if (s.equals("customers")) { customers(); } else if (s.equals("token")) { System.out.println(mapper.writeValueAsString(keycloak.getToken())); } else if (s.equals("id-token")) { System.out.println(mapper.writeValueAsString(keycloak.getIdToken())); } else if (s.equals("refresh")) { keycloak.refreshToken(); System.out.println( "Token refreshed: expires at " + Time.toDate(keycloak.getToken().getExpiration())); } else if (s.equals("exit")) { System.exit(0); } else { printHelp(); } } catch (ServerRequest.HttpFailure t) { System.out.println(t.getError()); } catch (Throwable t) { System.out.println(t.getMessage() != null ? t.getMessage() : t.getClass().toString()); } printDivider(); System.out.print("$ "); } }
From source file:ChatClient.java
public static void main(String[] args) throws Exception { int PORT = 4000; byte[] buf = new byte[1000]; DatagramPacket dgp = new DatagramPacket(buf, buf.length); DatagramSocket sk;// w ww. j av a2 s . c om sk = new DatagramSocket(PORT); System.out.println("Server started"); while (true) { sk.receive(dgp); String rcvd = new String(dgp.getData(), 0, dgp.getLength()) + ", from address: " + dgp.getAddress() + ", port: " + dgp.getPort(); System.out.println(rcvd); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String outMessage = stdin.readLine(); buf = ("Server say: " + outMessage).getBytes(); DatagramPacket out = new DatagramPacket(buf, buf.length, dgp.getAddress(), dgp.getPort()); sk.send(out); } }
From source file:DataLoader.java
public static void main(String[] args) throws IOException, ValidationException, LicenseException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { System.out.println(//from w w w. j a v a2 s .co m "System is initialising. Please wait for a few seconds then type your queries below once you see the prompt (->)"); C24.init().withLicence("/biz/c24/api/license-ads.dat"); // Create our application context - assumes the Spring configuration is in the classpath in a file called spring-config.xml ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml"); // ======================================================================== // DEMO // A simple command-line interface to allow us to query the GemFire regions // ======================================================================== GemfireTemplate template = context.getBean(GemfireTemplate.class); BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in)); boolean writePrompt = true; try { while (true) { if (writePrompt) { System.out.print("-> "); System.out.flush(); writePrompt = false; } if (br.ready()) { try { String request = br.readLine(); System.out.println("Running: " + request); SelectResults<Object> results = template.find(request); System.out.println(); System.out.println("Result:"); for (Object result : results.asList()) { System.out.println(result.toString()); } } catch (Exception ex) { System.out.println("Error executing last command " + ex.getMessage()); //ex.printStackTrace(); } writePrompt = true; } else { // Wait for a second and try again try { Thread.sleep(1000); } catch (InterruptedException ioEx) { break; } } } } catch (IOException ioe) { // Write any exceptions to stderr System.err.print(ioe); } }
From source file:CopyLines.java
public static void main(String[] args) throws IOException { BufferedReader inputStream = null; PrintWriter outputStream = null; try {//w ww . j av a 2 s . com inputStream = new BufferedReader(new FileReader("xanadu.txt")); outputStream = new PrintWriter(new FileWriter("characteroutput.txt")); String l; while ((l = inputStream.readLine()) != null) { outputStream.println(l); } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } }
From source file:com.sme.SmePoliceCheck.java
public static void main(String[] args) throws IOException, JSONException { // This API is for SME // After creating Police Check you should Upload documents and then submit the police check // 1-Create Police Check // 2-Upload Documents for Police Check ID // 3-Submit Police Check to Intercheck final String apiEndPoint = "https://secure.policecheckexpress.com.au/pce/api/portalCheckSme/new"; final String apiToken = "secure token"; try {/*from www. j a v a 2s . c om*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(apiEndPoint); //filling Portal Check with sample Data SmePortalCheck smePortalCheck = fillSampleData(); String parameters = fillParameters(smePortalCheck, apiToken); StringEntity input = new StringEntity(parameters); input.setContentType("application/json"); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String jsonText = readAll(br); JSONArray json = new JSONArray("[" + jsonText + "]"); JSONObject obj = (JSONObject) json.get(0); if (!(Boolean) obj.get("error")) { System.out.println(obj.get("message")); System.out.println("Invitation Id = " + obj.get("id")); } else { System.out.println("++++++++++++++++++++++++++"); System.out.println("Error = " + obj.get("message")); System.out.println("++++++++++++++++++++++++++"); } httpClient.getConnectionManager().shutdown(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:BufferedCopy.java
public static void main(String[] args) throws IOException { BufferedReader inputStream = null; BufferedWriter outputStream = null; try {//from w ww. j av a 2 s . co m inputStream = new BufferedReader(new FileReader("xanadu.txt")); outputStream = new BufferedWriter(new FileWriter("characteroutput.txt")); int c; while ((c = inputStream.read()) != -1) { outputStream.write(c); } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } }
From source file:examples.mail.java
public final static void main(String[] args) { String sender, recipient, subject, filename, server, cc; Vector ccList = new Vector(); BufferedReader stdin;/*from ww w.j a v a 2 s. c o m*/ FileReader fileReader = null; Writer writer; SimpleSMTPHeader header; SMTPClient client; Enumeration en; if (args.length < 1) { System.err.println("Usage: mail smtpserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); sender = stdin.readLine(); System.out.print("To: "); System.out.flush(); recipient = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleSMTPHeader(sender, recipient, subject); while (true) { System.out.print("CC <enter one address per line, hit enter to end>: "); System.out.flush(); // Of course you don't want to do this because readLine() may be null cc = stdin.readLine().trim(); if (cc.length() == 0) break; header.addCC(cc); ccList.addElement(cc); } System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); } client = new SMTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); client.connect(server); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("SMTP server refused connection."); System.exit(1); } client.login(); client.setSender(sender); client.addRecipient(recipient); en = ccList.elements(); while (en.hasMoreElements()) client.addRecipient((String) en.nextElement()); writer = client.sendMessageData(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } fileReader.close(); client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:net.java.sen.tools.MkCompoundTable.java
/** * Build compound word table.//from w ww . j a v a 2 s . c o m */ public static void main(String args[]) { ResourceBundle rb = ResourceBundle.getBundle("dictionary"); int pos_start = Integer.parseInt(rb.getString("pos_start")); int pos_size = Integer.parseInt(rb.getString("pos_size")); try { log.info("reading compound word information ... "); HashMap compoundTable = new HashMap(); log.info("load dic: " + rb.getString("compound_word_file")); BufferedReader dicStream = new BufferedReader(new InputStreamReader( new FileInputStream(rb.getString("compound_word_file")), rb.getString("dic.charset"))); String t; int line = 0; StringBuffer pos_b = new StringBuffer(); while ((t = dicStream.readLine()) != null) { CSVParser parser = new CSVParser(t); String csv[] = parser.nextTokens(); if (csv.length < (pos_size + pos_start)) { throw new RuntimeException("format error:" + line); } pos_b.setLength(0); for (int i = pos_start; i < (pos_start + pos_size - 1); i++) { pos_b.append(csv[i]); pos_b.append(','); } pos_b.append(csv[pos_start + pos_size - 1]); pos_b.append(','); for (int i = pos_start + pos_size; i < (csv.length - 2); i++) { pos_b.append(csv[i]); pos_b.append(','); } pos_b.append(csv[csv.length - 2]); compoundTable.put(pos_b.toString(), csv[csv.length - 1]); } dicStream.close(); log.info("done."); log.info("writing compound word table ... "); ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream(rb.getString("compound_word_table"))); os.writeObject(compoundTable); os.close(); log.info("done."); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:featureExtractor.popularityMeasure.java
public static void main(String[] args) throws IOException { //ReadKnownPopularityScores(); FileWriter fw = new FileWriter(Out_resultFile); BufferedWriter bw = new BufferedWriter(fw); FileReader inputFile = new FileReader(In_entities); BufferedReader bufferReader = new BufferedReader(inputFile); String line;//from w w w. j a va2 s.c om while ((line = bufferReader.readLine()) != null) { String[] row = line.split("\t"); double score = 0; String entityName = row[0].toLowerCase().trim(); System.out.println("Searching for : " + entityName); if (knownScore_table.containsKey(entityName)) { //System.out.println("Already known for: " + entityName); score = knownScore_table.get(entityName); } else { System.out.println("Not known for: " + entityName); String json = searchTest(entityName, "&scoring=entity"); try { score = ParseJSON_getScore(json); } catch (Exception e) { score = 0; } System.out.println("Putting : " + entityName); knownScore_table.put(entityName, score); } bw.write(row[0] + "\t" + score + "\n"); System.out.println(row[0]); } bw.close(); }