List of usage examples for java.lang System in
InputStream in
To view the source code for java.lang System in.
Click Source Link
From source file:MainClass.java
public static void main(String[] args) throws Exception { char[] passphrase = "sasquatch".toCharArray(); KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(new FileInputStream(".keystore"), passphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(keystore);/*from w w w . j av a2s . c o m*/ SSLContext context = SSLContext.getInstance("TLS"); TrustManager[] trustManagers = tmf.getTrustManagers(); context.init(null, trustManagers, null); SSLSocketFactory sf = context.getSocketFactory(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit { out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.close(); }
From source file:fitmon.Client.java
public static void main(String[] args) throws IOException, ClientProtocolException, NoSuchAlgorithmException, InvalidKeyException, SAXException, ParserConfigurationException { Food food = null;/*from ww w . j a v a 2s .co m*/ DietAPI dApi = new DietAPI(); JDBCConnection jdbcCon = new JDBCConnection(); ArrayList<Food> foodItems = dApi.getFood(); Scanner scan = new Scanner(System.in); Calendar currentDate = Calendar.getInstance(); //Get the current date SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); //format it as per your requirement String dateNow = formatter.format(currentDate.getTime()); System.out.println("Now the date is :=> " + dateNow); for (int i = 0; i < foodItems.size(); i++) { food = foodItems.get(i); System.out.println("ID : " + food.getFoodID()); System.out.println("servingID : " + food.getServingID()); System.out.println("Name : " + food.getItemName()); System.out.println("category : " + food.getCategory()); System.out.println("Quantity : " + food.getQuantity()); System.out.println("calories : " + food.getCalories()); System.out.println("fat : " + food.getFat()); System.out.println("carbs : " + food.getCarbs()); System.out.println("protein : " + food.getProtein()); System.out.println("fiber : " + food.getFiber()); System.out.println("sodium : " + food.getSodium()); System.out.println("sugar : " + food.getSugar()); System.out.println("cholesterol : " + food.getCholesterol()); System.out.println( "------------------------------------------------------------------------------------------------"); } System.out.println("Choose a meal......"); String mealType = scan.next(); System.out.println("Choose an item......"); String servingID = scan.next(); for (int j = 0; j < foodItems.size(); j++) { if (foodItems.get(j).getServingID() == null ? servingID == null : foodItems.get(j).getServingID().equals(servingID)) { food = foodItems.get(j); break; } } Diet diet = new CustomizedDiet(); diet.createDiet(food, mealType, dateNow); }
From source file:com.sm.transport.grizzly.TestServer.java
public static void main(String[] main) throws IOException { com.sm.transport.grizzly.TCPServer s = TCPServer.start(7120, new RequestCodecFilter(), new ServerFilter()); logger.info(s.toString());/* ww w . j av a2 s. c om*/ logger.info("Press any key to shutdownNow the server..."); System.in.read(); }
From source file:aula1.Aula1.java
/** * @param args the command line arguments *///from w w w.ja va 2 s . co m public static void main(String[] args) { Scanner dados = new Scanner(System.in); int escolha; double ini; double fim; String exp; String info; int sens = 0; boolean valida = true; do { System.out.println( "Decida a operao: 0 para montar grfico, 1 para calcular limite, 2 para calcular qualquer expresso"); escolha = dados.nextInt(); switch (escolha) { case 0: System.out.println("Informe o inicio do dominio"); ini = dados.nextDouble(); System.out.println("Informe o fim do dominio"); fim = dados.nextDouble(); System.out.println("Informe a quantidade de casas decimais desejadas: "); sens = dados.nextInt(); System.out.println("Informe a expresso: "); exp = dados.next(); double[] x = montaDominio(ini, fim, sens); calcula(x, exp); valida = false; break; case 1: System.out.println("Informe a expresso: "); exp = dados.next(); System.out.println("Informe o ponto limite: "); info = dados.next(); try { calculaLimite(exp, info); } catch (Exception ex) { System.out .println("Erro: " + ex.getMessage() + "Tentativade aplcao do teorema do confronto"); } valida = false; break; case 2: System.out.println("Informe a expresso:"); info = dados.next(); try { System.out.println(conversor(info, "0")); } catch (Exception ex) { System.out.println("Erro: " + ex.getMessage()); } valida = false; break; default: System.out.println("Escolha invlida!"); break; } } while (valida); // Double[] vet = new Double[3]; // vet = lerDados(); // montaDominio(vet[0], vet[1], vet[2].intValue()); // calculaLimite(3); }
From source file:com.sm.transport.grizzly.TestStringServer.java
public static void main(String[] main) throws IOException { com.sm.transport.grizzly.TCPServer s = TCPServer.start(7120, new StringFilter(), new EchoFilter(true)); logger.info(s.toString());//from w ww.java 2 s. c om logger.info("Press any key to shutdownNow the server..."); System.in.read(); }
From source file:net.cristcost.test.jpa.SpringLauncher.java
/** * @param args// w ww . j ava 2s .c o m * @throws IOException * @throws InterruptedException */ public static void main(String[] args) throws IOException { ConfigurableApplicationContext springContext = new ClassPathXmlApplicationContext( "META-INF/spring/beans.xml"); System.out.println("Press ENTER to exit"); System.in.read(); System.out.println("exit"); springContext.close(); }
From source file:base64.EncodeBase64.java
public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter string to encode (input is not escaped):"); String originalString = reader.readLine(); String encodedBase64String = Base64.encodeBase64String(originalString.getBytes()); System.out.println("Your encoded Base64 string :"); System.out.println(encodedBase64String); }
From source file:Redirect.java
public static void main(String args[]) throws Exception { PrintStream origOut = System.out; PrintStream origErr = System.err; InputStream stdin = null;//from www . j a va 2 s. co m stdin = new FileInputStream("Redirect.in"); PrintStream stdout = null; stdout = new PrintStream(new FileOutputStream("Redirect.out")); PrintStream stderr = null; stderr = new PrintStream(new FileOutputStream("Redirect.err")); origOut.println("1"); System.out.println("2"); origOut.println("3"); System.err.println("4"); origErr.println("5"); System.setIn(stdin); System.setOut(stdout); System.setErr(stderr); origOut.println("\nR"); System.out.println("T"); origOut.println("Tq"); System.err.println("Tqw"); origErr.println("Test"); origOut.println("\nRedirect: Round #3"); int inChar = 0; while (-1 != inChar) { try { inChar = System.in.read(); } catch (Exception e) { // Clean up the output and bail. origOut.print("\n"); break; } origOut.write(inChar); } stdin.close(); stdout.close(); stderr.close(); System.exit(0); }
From source file:FlightInfo.java
public static void main(String args[]) { String to, from;/*from w w w . j a v a 2 s.c o m*/ Optimal ob = new Optimal(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); boolean done = false; FlightInfo f; ob.setup(); try { System.out.print("From? "); from = br.readLine(); System.out.print("To? "); to = br.readLine(); do { ob.isflight(from, to); if (ob.btStack.size() == 0) done = true; else { ob.route(to); ob.btStack = new Stack(); } } while (!done); // Display optimal solution. if (ob.optimal != null) { System.out.println("Optimal solution is: "); int num = ob.optimal.size(); for (int i = 0; i < num; i++) { f = (FlightInfo) ob.optimal.pop(); System.out.print(f.from + " to "); } System.out.println(to); System.out.println("Distance is " + ob.minDist); } } catch (IOException exc) { System.out.println("Error on input."); } }
From source file:edu.eci.arsw.loannetsim.LoanNetworkSimulation.java
public static void main(String args[]) throws InterruptedException, IOException { ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); int balancesSum = 0; List<Lender> lenders = setupLoanNetwork(NUMOF_LENDERS, ac); if (lenders != null) { for (Lender im : lenders) { new Thread(im).start(); }//from w ww . j av a2s .c o m } while (true) { Thread.sleep(10000); FixedMoneyLender.pause(); System.out.println("*** PRESS ENTER TO VIEW STATISTICS ***"); System.in.read(); balancesSum = 0; for (Lender ln : lenders) { balancesSum += ln.getBalance(); } System.out.println("Sum of balances:" + balancesSum); System.out.println("Press enter to continue simulation or Ctrl+C to abort..."); System.in.read(); FixedMoneyLender.resume(); synchronized (lenders) { lenders.notifyAll(); } } }