List of usage examples for java.io Console writer
public PrintWriter writer()
From source file:Main.java
public static void main(String[] args) throws Exception { // creates a console object Console cnsl = System.console(); // if console is not null if (cnsl != null) { // creates new print writer PrintWriter out = cnsl.writer(); // prints out.println("Here is The Optimus Prime!!"); }//from w ww. jav a 2 s . co m }
From source file:goeurotest.GoEuroTest.java
/** * @param args the command line arguments *///from w w w.j a v a 2 s . c om public static void main(String[] args) { Console console = System.console(); if (args.length != 1) { if (console != null) console.writer().println("Usage: java -jar GoEuroTest.jar <CITY_NAME>"); return; } URL url; try { url = new URL("http://api.goeuro.com/api/v2/position/suggest/en/" + args[0]); } catch (MalformedURLException ex) { if (console != null) console.writer().println("Malformed URL. Make sure the first parameter is the name of the city."); return; } String json; try { json = IOUtils.toString(url); } catch (IOException ex) { if (console != null) console.writer().println("Unable to contact the GoEuro API"); return; } JsonParser parser = new JsonParser(); try { JsonArray cities = parser.parse(json).getAsJsonArray(); if (cities.size() == 0) { if (console != null) console.writer().println("No results found"); return; } for (int i = 0; i < cities.size(); i++) { JsonObject city = cities.get(i).getAsJsonObject(); String id = city.get("_id").getAsString(); String name = city.get("name").getAsString(); String type = city.get("type").getAsString(); JsonObject geo_position = city.get("geo_position").getAsJsonObject(); String latitude = geo_position.get("latitude").getAsString(); String longitude = geo_position.get("longitude").getAsString(); String entry = id + "," + name + "," + type + "," + latitude + "," + longitude; System.out.println(entry); } } catch (Exception e) { if (console != null) console.writer().println("Malformed API response."); } }
From source file:org.hawkular.wildfly.agent.installer.AgentInstaller.java
/** * Reads password from the console (stdin). * * @param message to present before reading * @return password or null if console is not available *//* ww w .ja v a2 s .c om*/ private static String readPasswordFromStdin(String message) { Console console = System.console(); if (console == null) { return null; } console.writer().write(message); console.writer().flush(); return String.valueOf(console.readPassword()); }
From source file:org.olamy.puzzle.robot.input.cli.RobotMoverInputBuilderCli.java
@Override public RobotMoverInput getRobotMoverInput() throws RobotMoverInputException { try {/*from w w w .ja va2 s . c o m*/ Console console = System.console(); PrintWriter writer = console.writer(); writer.write("Hello in robot mover, have Fun ! " + SystemUtils.LINE_SEPARATOR); // so we could accept the user to configure the size of the table /** writer.write( "Initial Table (sample 5 5) : " ); console.flush(); String tablePos = console.readLine(); Table table = RobotOrderUtils.buildTable( tablePos ); */ RobotMoverInput moverInput = new RobotMoverInput(Table.DEFAULT_TABLE); moverInput.setRobotOrder(getRobotOrder(console, writer, moverInput.getTable())); return moverInput; } catch (Exception e) { throw new RobotMoverInputException(e.getMessage(), e); } }
From source file:org.xlrnet.tibaija.Application.java
private static VirtualCalculator getDefaultCalculator(CodeProvider codeProvider) throws IOException { Reader reader;/*from w w w . j av a2s .c o m*/ Writer writer; if (System.console() != null) { Console console = System.console(); reader = console.reader(); writer = console.writer(); LOGGER.debug("Initialised native system console"); } else { reader = new InputStreamReader(System.in); writer = new OutputStreamWriter(System.out); LOGGER.debug("Initialised system I/O streams"); } CalculatorIO io = new ConsoleIO(reader, writer); CalculatorMemory memory = new DefaultCalculatorMemory(); HomeScreen homeScreen = new NullHomeScreen(); FontRegistry fontRegistry = new FontRegistry(); fontRegistry.registerFont(Paths.get("largeFont.json"), FontConstants.FONT_LARGE); fontRegistry.registerFont(Paths.get("smallFont.json"), FontConstants.FONT_SMALL); ExecutionEnvironment.newEnvironment(memory, io, codeProvider, homeScreen, fontRegistry); return new TI83Plus(memory, io, codeProvider); }