List of usage examples for java.io InputStreamReader InputStreamReader
public InputStreamReader(InputStream in)
From source file:org.wso2.charon3.samples.group.sample01.CreateGroupSample.java
public static void main(String[] args) { try {//from www . j a v a 2s.com String url = "http://localhost:8080/scim/v2/Groups"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // Setting basic post request con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/scim+json"); // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(createRequestBody); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); BufferedReader in; if (responseCode == HttpURLConnection.HTTP_CREATED) { // success in = new BufferedReader(new InputStreamReader(con.getInputStream())); } else { in = new BufferedReader(new InputStreamReader(con.getErrorStream())); } String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); //printing result from response System.out.println("Response Code : " + responseCode); System.out.println("Response Message : " + con.getResponseMessage()); System.out.println("Response Content : " + response.toString()); } catch (ProtocolException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:SimpleCalcScanner.java
public static void main(String[] av) throws IOException { if (av.length == 0) new SimpleCalcScanner(new InputStreamReader(System.in)).doCalc(); else// w w w .j av a 2s. c om for (int i = 0; i < av.length; i++) new SimpleCalcScanner(av[i]).doCalc(); }
From source file:com.iveely.computing.Program.java
/** * @param args the command line arguments * @throws java.io.IOException/*from w ww . ja v a 2 s . co m*/ */ public static void main(String[] args) throws IOException { if (args != null && args.length > 0) { logger.info("start computing with arguments:" + String.join(",", args)); String type = args[0].toLowerCase(Locale.CHINESE); switch (type) { case "master": launchMaster(); return; case "slave": if (args.length == 4) { ConfigWrapper.get().getSlave().setPort(Integer.parseInt(args[1])); ConfigWrapper.get().getSlave().setSlot(Integer.parseInt(args[2])); ConfigWrapper.get().getSlave().setSlotCount(Integer.parseInt(args[3])); } launchSlave(); return; case "supervisor": launchSupervisor(); return; case "console": launchConsole(); return; } } logger.error("arguments error,example [master | supervisor | slave | console]"); System.out.println("press any keys to exit..."); new BufferedReader(new InputStreamReader(System.in)).readLine(); }
From source file:com.icesoft.applications.faces.address.XWrapperUtil.java
public static void main(String[] args) { if (log.isDebugEnabled()) { log.debug("Converting database..."); }//w ww . ja va2 s .c om //load the CSV file InputStream is = MatchAddressDB.class.getResourceAsStream(CSV_ADDRESS_DB); BufferedReader buff = new BufferedReader(new InputStreamReader(is)); XMLEncoder xEncode = null; XAddressDataWrapper xData; //open the XML encoder and attempt to write the xml file try { xEncode = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(XML_GZ_ADDRESS_DB))); } catch (FileNotFoundException ex) { log.error("Database could not be written.", ex); } //first line char[] line = getNextLine(buff); while (line != null) { //get three strings within quotes String addressValues[] = new String[3]; int stringValueStart = 0, stringValueEnd; for (int i = 0; i < 3; i++) { //opening quote while (line[stringValueStart++] != '\"') { } stringValueEnd = stringValueStart + 1; //closing quote while (line[stringValueEnd] != '\"') { stringValueEnd++; } //value addressValues[i] = new String(line, stringValueStart, stringValueEnd - stringValueStart); stringValueStart = stringValueEnd + 1; } //assign the data to the wrapper xData = new XAddressDataWrapper(); xData.setCity(addressValues[1]); xData.setState(addressValues[2]); xData.setZip(addressValues[0]); //read the next line (entry) in the CSV file line = getNextLine(buff); } //close the XML Encoder try { xEncode.close(); } catch (NullPointerException npe) { log.error("Could not close XML Encoder.", npe); return; } if (log.isDebugEnabled()) { log.debug("Closed XML Encoder."); } }
From source file:com.quix.aia.cn.imo.mapper.UrlForUserData.java
public static void main(String[] args) { // TODO Auto-generated method stub UserAuthResponds userAuth = new UserAuthResponds(); try {//from ww w . j a v a 2 s . c om GsonBuilder builder = new GsonBuilder(); DefaultHttpClient httpClient = new DefaultHttpClient(); String username = "", psw = "", co = ""; username = "NSNP306"; psw = "A111111A"; co = "0986"; HttpGet getRequest = new HttpGet("http://211.144.219.243/isp/rest/index.do?isAjax=true&account=" + username + "&co=" + co + "&password=" + psw + ""); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); 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); Gson googleJson = new Gson(); userAuth = googleJson.fromJson(output, UserAuthResponds.class); System.out.println("Success " + userAuth.getSuccess()); if (userAuth.getSuccess().equals("1")) { System.out.println("Login successfully Done"); } else { System.out.println("Login Failed "); } } httpClient.getConnectionManager().shutdown(); // googleJson = builder.create(); // Type listType = new TypeToken<List<UserAuthResponds>>() {}.getType(); } catch (ClientProtocolException e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } }
From source file:org.jaqpot.core.service.client.jpdi.JPDIClientFactory.java
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException { CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create().build(); asyncClient.start();/*from w ww.j a v a 2 s. co m*/ HttpGet request = new HttpGet("http://www.google.com"); request.addHeader("Accept", "text/html"); Future f = asyncClient.execute(request, new FutureCallback<HttpResponse>() { @Override public void completed(HttpResponse t) { System.out.println("completed"); try { String result = new BufferedReader(new InputStreamReader(t.getEntity().getContent())).lines() .collect(Collectors.joining("\n")); System.out.println(result); } catch (IOException ex) { Logger.getLogger(JPDIClientFactory.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedOperationException ex) { Logger.getLogger(JPDIClientFactory.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void failed(Exception excptn) { System.out.println("failed"); } @Override public void cancelled() { System.out.println("cancelled"); } }); f.get(); asyncClient.close(); }
From source file:com.asquareb.kaaval.MachineKey.java
/** * Main method to execute as a command line utility. Provides the option to * encrypt a string, decrypt a encrypted string or exit from the program *//*from w w w.ja v a2s.c o m*/ public static void main(String[] args) { String originalPassword = null; String encryptedPassword = null; try { final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter E - Encrypt,D - Decrypt,X - Exit :"); final String choice = cin.readLine(); final Random rand = new Random(); boolean phraseCorrect = false; String app = null; if (choice.equalsIgnoreCase("E")) { System.out.print("Enter the string to encrypt :"); originalPassword = cin.readLine(); System.out.println("Choose a phrase of min 8 chars in length "); System.out.println(" Also the password should include 2 Cap,"); System.out.println(" 2 small letters,2 numeric and 2 non alpha numeric chars"); while (!phraseCorrect) { System.out.print("Enter a phrase to encrypt :"); password = cin.readLine().toCharArray(); phraseCorrect = PasswordRules.verifyPassword(password); } System.out.print("Enter application code :"); app = cin.readLine(); app += (rand.nextInt(10000)); encryptedPassword = encrypt(originalPassword, app); System.out.println("Encrypted password :" + encryptedPassword); System.out.println("Key stored in :" + app); System.out.println("*** Provide the encrypted string to app team"); System.out.println("*** Store the key file in a secure durectory"); System.out.println("*** Inform the key file name and location to app team"); } else if (choice.equalsIgnoreCase("D")) { System.out.print("Enter the string to Decrypt :"); encryptedPassword = cin.readLine(); System.out.print("Enter the name of key file :"); app = cin.readLine(); final String decryptedPassword = decrypt(encryptedPassword, app); System.out.print("Decrypted string :" + decryptedPassword); } return; } catch (KaavalException e) { e.PrintProtectException(); } catch (Exception e) { e.printStackTrace(); } }
From source file:EchoClient.java
public static void main(String[] args) throws IOException { Socket echoSocket = null;//from w ww. j a va 2 s. c o m PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: taranis."); System.exit(1); } BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } out.close(); in.close(); stdIn.close(); echoSocket.close(); }
From source file:org.hyperic.hq.hqapi1.tools.PasswordEncryptor.java
public static void main(String[] args) throws Exception { String password1 = String.valueOf(PasswordField.getPassword(System.in, "Enter password: ")); String password2 = String.valueOf(PasswordField.getPassword(System.in, "Re-Enter password: ")); String encryptionKey = "defaultkey"; if (password1.equals(password2)) { System.out.print("Encryption Key: "); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); encryptionKey = in.readLine();//w ww . j a v a 2 s . c o m if (encryptionKey.length() < 8) { System.out.println("Encryption key too short. Please use at least 8 characters"); System.exit(-1); } } else { System.out.println("Passwords don't match"); System.exit(-1); } System.out.println("The encrypted password is " + encryptPassword(password1, encryptionKey)); }
From source file:PSFormatter.java
public static void main(String[] av) throws IOException { if (av.length == 0) new PSFormatter(new InputStreamReader(System.in)).process(); else/*from w w w . j a v a2s.c om*/ for (int i = 0; i < av.length; i++) { new PSFormatter(av[i]).process(); } }