Example usage for java.lang System in

List of usage examples for java.lang System in

Introduction

In this page you can find the example usage for java.lang System in.

Prototype

InputStream in

To view the source code for java.lang System in.

Click Source Link

Document

The "standard" input stream.

Usage

From source file:ExecSQL.java

public static void main(String args[]) {
        try {/*from www .j a  v a 2 s .co m*/
            Scanner in;
            if (args.length == 0)
                in = new Scanner(System.in);
            else
                in = new Scanner(new File(args[0]));

            Connection conn = getConnection();
            try {
                Statement stat = conn.createStatement();

                while (true) {
                    if (args.length == 0)
                        System.out.println("Enter command or EXIT to exit:");

                    if (!in.hasNextLine())
                        return;

                    String line = in.nextLine();
                    if (line.equalsIgnoreCase("EXIT"))
                        return;
                    if (line.trim().endsWith(";")) // remove trailing semicolon
                    {
                        line = line.trim();
                        line = line.substring(0, line.length() - 1);
                    }
                    try {
                        boolean hasResultSet = stat.execute(line);
                        if (hasResultSet)
                            showResultSet(stat);
                    } catch (SQLException ex) {
                        for (Throwable e : ex)
                            e.printStackTrace();
                    }
                }
            } finally {
                conn.close();
            }
        } catch (SQLException e) {
            for (Throwable t : e)
                t.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

From source file:org.fusesource.cloudmix.tests.consumer.Main.java

public static void main(String[] args) {
    if (args.length > 0 && args[0].equals("-debug")) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }/*from w  ww.  ja v a2 s  .  co m*/
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/context.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:examples.weatherTelnet.java

public final static void main(String[] args) {
    TelnetClient telnet;//  w  ww  . j  a  v a  2s.  c o m

    telnet = new TelnetClient();

    try {
        telnet.connect("rainmaker.wunderground.com", 3000);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(), System.in, System.out);

    try {
        telnet.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    System.exit(0);
}

From source file:com.bow.rest.RestConsumer.java

public static void main(String[] args) throws Exception {
    String config = RestConsumer.class.getPackage().getName().replace('.', '/') + "/rest-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//from w w  w  .  ja  va  2 s .  c o  m
    AnotherUserRestService userService = (AnotherUserRestService) context.getBean("anotherUserRestService");

    User user = new User(1L, "larrypage");
    System.out.println("SUCCESS: registered user with id " + userService.registerUser(user).getId());

    RpcContext.getContext().setAttachment("clientName", "demo");
    RpcContext.getContext().setAttachment("clientImpl", "dubbox");
    System.out.println("SUCCESS: got user " + userService.getUser(1L));
    System.in.read();
}

From source file:org.fusesource.cloudmix.tests.broker.Main.java

public static void main(String[] args) {
    if (verbose || (args.length > 0 && args[0].equals("-debug"))) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }//ww  w . j  a v  a2  s . c  o  m
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/activemq.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:com.rdio.simple.examples.CommandLine.java

public static void main(String[] args) throws IOException, JSONException {
    ConsumerCredentials consumerCredentials = new ConsumerCredentials();
    RdioClient rdio = new RdioCoreClient(consumerCredentials);

    try {//from  w ww  .  j a v a 2 s  .  c  o  m
        RdioClient.AuthState authState = rdio.beginAuthentication("oob");
        System.out.println("Go to: " + authState.url);
        System.out.print("Then enter the code: ");
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String verifier = reader.readLine().trim();
        RdioClient.Token accessToken = rdio.completeAuthentication(verifier, authState.requestToken);
        rdio = new RdioCoreClient(consumerCredentials, accessToken);

        try {
            JSONObject response = new JSONObject(rdio.call("getPlaylists"));
            JSONArray playlists = (JSONArray) ((JSONObject) response.get("result")).get("owned");
            for (int i = 0; i < playlists.length(); i++) {
                JSONObject playlist = playlists.getJSONObject(i);
                System.out.println(playlist.getString("shortUrl") + "\t" + playlist.getString("name"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (RdioClient.RdioException e) {
        System.err.println("Rdio Error: " + e.toString());
    }
}

From source file:net.airvantage.sample.AirVantageExampleFlow2.java

public static void main(String[] args) {

    String apiUrl = "https://na.airvantage.net/api";
    // Replace these with your own api key and secret
    String apiKey = "your_app_id";
    String apiSecret = "your_api_secret";

    String login = null;//from  w w w .java 2  s . c o  m
    String password = null;
    String access_token = null;

    Scanner in = new Scanner(System.in);

    System.out.println("=== AirVantage's OAuth Workflow ===");
    System.out.println();

    // Obtain User/Password
    System.out.println("Enter your login:");
    System.out.print(">>");
    login = in.nextLine();
    System.out.println();
    System.out.println("...and your password:");
    System.out.print(">>");
    password = in.nextLine();
    System.out.println();

    // Get the Access Token
    System.out.println("Getting the Access Token...");
    System.out.println(apiUrl + "/oauth/token?grant_type=password&username=" + login + "&password=" + password
            + "&client_id=" + apiKey + "&client_secret=" + apiSecret);
    try {
        access_token = Request
                .Get(apiUrl + "/oauth/token?grant_type=password&username=" + login + "&password=" + password
                        + "&client_id=" + apiKey + "&client_secret=" + apiSecret)
                .execute().handleResponse(new ResponseHandler<String>() {

                    public String handleResponse(final HttpResponse response) throws IOException {
                        StatusLine statusLine = response.getStatusLine();
                        HttpEntity entity = response.getEntity();
                        if (statusLine.getStatusCode() >= 300) {
                            throw new HttpResponseException(statusLine.getStatusCode(),
                                    statusLine.getReasonPhrase());
                        }
                        if (entity == null) {
                            throw new ClientProtocolException("Response contains no content");
                        }

                        try {
                            String content = IOUtils.toString(entity.getContent());
                            JSONObject result = new JSONObject(content);
                            return result.getString("access_token");
                        } catch (JSONException e) {
                            throw new ClientProtocolException("Malformed JSON", e);
                        }
                    }

                });

        System.out.println("Got the Access Token!");
        System.out.println("(if you're curious it looks like this: " + access_token + " )");
        System.out.println();

        // Now let's go and ask for a protected resource!
        System.out.println("Now we're going to get info about the current user...");

        JSONObject result = Request.Get(apiUrl + "/v1/users/current?access_token=" + access_token).execute()
                .handleResponse(new ResponseHandler<JSONObject>() {

                    public JSONObject handleResponse(final HttpResponse response) throws IOException {
                        StatusLine statusLine = response.getStatusLine();
                        HttpEntity entity = response.getEntity();
                        if (statusLine.getStatusCode() >= 300) {
                            throw new HttpResponseException(statusLine.getStatusCode(),
                                    statusLine.getReasonPhrase());
                        }
                        if (entity == null) {
                            throw new ClientProtocolException("Response contains no content");
                        }

                        try {
                            String content = IOUtils.toString(entity.getContent());
                            return new JSONObject(content);
                        } catch (JSONException e) {
                            throw new ClientProtocolException("Malformed JSON", e);
                        }
                    }

                });

        System.out.println("Got it! Let's see what we found...");
        System.out.println();
        System.out.println(result.toString());

        System.out.println();
        System.out.println("That's it man! Go and build something awesome with AirVantage! :)");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Standard.java

public static void main(String args[]) throws IOException {
    BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
    String number;/*from  w  ww .  ja v  a2s  .  c om*/
    int total = 0;

    while ((number = cin.readLine()) != null) {
        try {
            total += Integer.parseInt(number);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number in input");
            System.exit(1);
        }
    }
    System.out.println(total);
}

From source file:com.github.xbn.examples.lang.non_xbn.VerifyUserInputIsANumberWithIsNumber.java

public static final void main(String[] ignored) {

    int num = -1;
    boolean isNum = false;

    do {//www.j av a 2s .c o m
        System.out.print("Number please: ");
        String strInput = (new Scanner(System.in)).next();
        if (!NumberUtils.isNumber(strInput)) {
            System.out.println(strInput + " is not a number. Try again.");
        } else {
            //Safe to convert
            num = Integer.parseInt(strInput);
            isNum = true;
        }
    } while (!isNum);

    System.out.println("Number: " + num);
}

From source file:ch.qos.logback.decoder.cli.Main.java

/**
 * Entry point for command-line interface
 *
 * @param args the command-line parameters
 *//*from  w  w  w .jav  a 2s.com*/
static public void main(String[] args) {
    MainArgs mainArgs = null;
    try {
        mainArgs = new MainArgs(args);

        // handle help and version queries
        if (mainArgs.queriedHelp()) {
            mainArgs.printUsage();
        } else if (mainArgs.queriedVersion()) {
            mainArgs.printVersion();

            // normal processing
        } else {
            if (mainArgs.isDebugMode()) {
                enableVerboseLogging();
            }

            BufferDecoder decoder = new BufferDecoder();
            decoder.setLayoutPattern(mainArgs.getLayoutPattern());

            BufferedReader reader = null;
            if (StringUtils.defaultString(mainArgs.getInputFile()).isEmpty()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
            } else {
                reader = new BufferedReader(new FileReader(mainArgs.getInputFile()));
            }

            decoder.decode(reader);
        }
    } catch (Exception e) {
        System.err.println("error: " + e.getMessage());
    }
}