List of usage examples for java.io InputStreamReader InputStreamReader
public InputStreamReader(InputStream in)
From source file:org.apache.olingo.odata2.fit.mapping.MappingTest.java
public static void main(final String[] args) { final TestServer server = new TestServer(ServletType.JAXRS_SERVLET); try {// ww w . j a va2 s .co m server.startServer(MapFactory.class); System.out.println("Press any key to exit"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } catch (final IOException e) { e.printStackTrace(System.err); } finally { server.stopServer(); } }
From source file:com.tbodt.trp.TheRapidPermuter.java
/** * Main method for The Rapid Permuter.//from ww w . jav a 2s. c om * * @param args * @throws IOException */ public static void main(String[] args) throws IOException { CommandProcessor.processCommand("\"\": remove(\"\") in([words])").ifPresent(x -> x.forEach(y -> { })); // to load all the classes we need try { cmd = new BasicParser().parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); return; } if (Arrays.asList(cmd.getOptions()).contains(help)) { // another way commons cli is severely broken new HelpFormatter().printHelp("trp", options); return; } if (cmd.hasOption('c')) doCommand(cmd.getOptionValue('c')); else { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("trp> "); String input; while ((input = in.readLine()) != null) { if (input.equals("exit")) return; // exit doCommand(input); System.out.print("trp> "); } } }
From source file:com.anteam.demo.logback.PostDemo.java
public static void main(String[] args) { StringEntity stringEntity = new StringEntity("this is the log2.", ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost("http://10.16.0.207:9000"); post.setEntity(stringEntity);//w w w.ja v a2s.co m HttpClient httpclient = new DefaultHttpClient(); // Execute the request HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } httpclient.getConnectionManager().shutdown(); } }
From source file:com.anteam.demo.httpclient.PostDemo.java
public static void main(String[] args) { StringEntity stringEntity = new StringEntity("this is the log2.", ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost("http://127.0.0.1:9000"); post.setEntity(stringEntity);//ww w.j a v a 2 s.co m HttpClient httpclient = new DefaultHttpClient(); // Execute the request HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } httpclient.getConnectionManager().shutdown(); } }
From source file:Naive.java
public static void main(String[] args) throws Exception { // Basic access authentication setup String key = "CHANGEME: YOUR_API_KEY"; String secret = "CHANGEME: YOUR_API_SECRET"; String version = "preview1"; // CHANGEME: the API version to use String practiceid = "000000"; // CHANGEME: the practice ID to use // Find the authentication path Map<String, String> auth_prefix = new HashMap<String, String>(); auth_prefix.put("v1", "oauth"); auth_prefix.put("preview1", "oauthpreview"); auth_prefix.put("openpreview1", "oauthopenpreview"); URL authurl = new URL("https://api.athenahealth.com/" + auth_prefix.get(version) + "/token"); HttpURLConnection conn = (HttpURLConnection) authurl.openConnection(); conn.setRequestMethod("POST"); // Set the Authorization request header String auth = Base64.encodeBase64String((key + ':' + secret).getBytes()); conn.setRequestProperty("Authorization", "Basic " + auth); // Since this is a POST, the parameters go in the body conn.setDoOutput(true);/*from w ww . j a v a 2 s . co m*/ String contents = "grant_type=client_credentials"; DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(contents); wr.flush(); wr.close(); // Read the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); // Decode from JSON and save the token for later String response = sb.toString(); JSONObject authorization = new JSONObject(response); String token = authorization.get("access_token").toString(); // GET /departments HashMap<String, String> params = new HashMap<String, String>(); params.put("limit", "1"); // Set up the URL, method, and Authorization header URL url = new URL("https://api.athenahealth.com/" + version + "/" + practiceid + "/departments" + "?" + urlencode(params)); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Bearer " + token); rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); response = sb.toString(); JSONObject departments = new JSONObject(response); System.out.println(departments.toString()); // POST /appointments/{appointmentid}/notes params = new HashMap<String, String>(); params.put("notetext", "Hello from Java!"); url = new URL("https://api.athenahealth.com/" + version + "/" + practiceid + "/appointments/1/notes"); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Bearer " + token); // POST parameters go in the body conn.setDoOutput(true); contents = urlencode(params); wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(contents); wr.flush(); wr.close(); rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); response = sb.toString(); JSONObject note = new JSONObject(response); System.out.println(note.toString()); }
From source file:org.kuali.kfs.rest.AccountingPeriodCloseJob.java
public static void main(String[] args) { try {/* w w w . j a v a 2s. c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost request = new HttpPost("http://localhost:8080/kfs-dev/coa/accounting_periods/close"); request.addHeader("accept", "application/json"); request.addHeader("content-type", "application/json"); request.addHeader("authorization", "NSA_this_is_for_you"); StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("\"description\":\"Document: The Next Generation\","); sb.append("\"universityFiscalYear\": 2016,"); sb.append("\"universityFiscalPeriodCode\": \"03\""); sb.append("}"); StringEntity data = new StringEntity(sb.toString()); request.setEntity(data); HttpResponse response = httpClient.execute(request); System.out.println("Status Code: " + response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Indent.java
public static void main(String[] av) { Indent c = new Indent(); switch (av.length) { case 0:// w w w . jav a 2 s.co m c.process(new BufferedReader(new InputStreamReader(System.in))); break; default: for (int i = 0; i < av.length; i++) try { c.process(new BufferedReader(new FileReader(av[i]))); } catch (FileNotFoundException e) { System.err.println(e); } } }
From source file:it.codestudio.callbyj.CallByJ.java
/** * The main method./*from www .jav a 2s. com*/ * * @param args the arguments */ public static void main(String[] args) { options.addOption("aCom", "audio_com", true, "Specify serial COM port for audio streaming (3G APPLICATION ...)"); options.addOption("cCom", "command_com", true, "Specify serial COM port for modem AT command (PC UI INTERFACE ...)"); options.addOption("p", "play_message", false, "Play recorded message instead to respond with audio from mic"); options.addOption("h", "help", false, "Print help for this application"); try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String audioCOM = ""; String commandCOM = ""; Boolean playMessage = false; args = Utils.fitlerNullString(args); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("aCom")) { audioCOM = cmd.getOptionValue("aCom"); ; } if (cmd.hasOption("cCom")) { commandCOM = cmd.getOptionValue("cCom"); ; } if (cmd.hasOption("p")) { playMessage = true; } if (audioCOM != null && commandCOM != null && !audioCOM.isEmpty() && !commandCOM.isEmpty()) { comManager = ComManager.getInstance(commandCOM, audioCOM, playMessage); } else { HelpFormatter f = new HelpFormatter(); f.printHelp("\r Exaple: CallByJ -aCom COM11 -cCom COM10 \r OptionsTip", options); return; } options = new Options(); options.addOption("h", "help", false, "Print help for this application"); options.addOption("p", "pin", true, "Specify pin of device, if present"); options.addOption("c", "call", true, "Start call to specified number"); options.addOption("e", "end", false, "End all active call"); options.addOption("t", "terminate", false, "Terminate application"); options.addOption("r", "respond", false, "Respond to incoming call"); comManager.startModemCommandManager(); while (true) { try { String[] commands = { br.readLine() }; commands = Utils.fitlerNullString(commands); cmd = parser.parse(options, commands); if (cmd.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("OptionsTip", options); } if (cmd.hasOption('p')) { String devicePin = cmd.getOptionValue("p"); comManager.insertPin(devicePin); } if (cmd.hasOption('c')) { String numberToCall = cmd.getOptionValue("c"); comManager.sendCommandToModem(ATCommands.CALL, numberToCall); } if (cmd.hasOption('r')) { comManager.respondToIncomingCall(); } if (cmd.hasOption('e')) { comManager.sendCommandToModem(ATCommands.END_CALL); } if (cmd.hasOption('t')) { comManager.sendCommandToModem(ATCommands.END_CALL); comManager.terminate(); System.out.println("CallByJ closed!"); break; //System.exit(0); } } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (comManager != null) comManager.terminate(); } }
From source file:com.ikanow.aleph2.remote.es_tests.SimpleReadableCrudTest.java
public static void main(final String args[]) throws Exception { if (args.length < 1) { System.out.println("CLI: <host>"); System.exit(-1);/* w ww. j a v a2 s. co m*/ } final String temp_dir = System.getProperty("java.io.tmpdir") + File.separator; Config config = ConfigFactory .parseReader(new InputStreamReader( SimpleReadableCrudTest.class.getResourceAsStream("/test_es_remote.properties"))) .withValue("globals.local_root_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("globals.local_cached_jar_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("globals.distributed_root_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("globals.local_yarn_config_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("MongoDbManagementDbService.mongodb_connection", ConfigValueFactory.fromAnyRef(args[0] + ":27017")) .withValue("ElasticsearchCrudService.elasticsearch_connection", ConfigValueFactory.fromAnyRef(args[0] + ":9300")); final SimpleReadableCrudTest app = new SimpleReadableCrudTest(); final Injector app_injector = ModuleUtils.createTestInjector(Arrays.asList(), Optional.of(config)); app_injector.injectMembers(app); app.runTest(); System.exit(0); }
From source file:org.sbq.batch.mains.ActivityEmulator.java
public static void main(String[] vars) throws IOException { System.out.println("ActivityEmulator - STARTED."); ActivityEmulator activityEmulator = new ActivityEmulator(); activityEmulator.begin();//from w w w. j a va 2 s .com System.out.println("Enter your command: >"); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String command = null; while (!"stop".equals(command = in.readLine())) { if ("status".equals(command)) { List<String> onlineUsers = new LinkedList<String>(); for (Map.Entry<String, AtomicBoolean> entry : activityEmulator.getUserStatusByLogin().entrySet()) { if (entry.getValue().get()) { onlineUsers.add(entry.getKey()); } } System.out.println("Users online: " + Arrays.toString(onlineUsers.toArray())); System.out.println("Number of cycles left: " + activityEmulator.getBlockingQueue().size()); } System.out.println("Enter your command: >"); } activityEmulator.stop(); System.out.println("ActivityEmulator - STOPPED."); }