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:SendMail.java

public static void main(String[] args) {
    try {/*  w  ww.j a  v  a2  s  . c  o m*/
        // If the user specified a mailhost, tell the system about it.
        if (args.length >= 1)
            System.getProperties().put("mail.host", args[0]);

        // A Reader stream to read from the console
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        // Ask the user for the from, to, and subject lines
        System.out.print("From: ");
        String from = in.readLine();
        System.out.print("To: ");
        String to = in.readLine();
        System.out.print("Subject: ");
        String subject = in.readLine();

        // Establish a network connection for sending mail
        URL u = new URL("mailto:" + to); // Create a mailto: URL
        URLConnection c = u.openConnection(); // Create its URLConnection
        c.setDoInput(false); // Specify no input from it
        c.setDoOutput(true); // Specify we'll do output
        System.out.println("Connecting..."); // Tell the user
        System.out.flush(); // Tell them right now
        c.connect(); // Connect to mail host
        PrintWriter out = // Get output stream to host
                new PrintWriter(new OutputStreamWriter(c.getOutputStream()));

        // We're talking to the SMTP server now.
        // Write out mail headers. Don't let users fake the From address
        out.print("From: \"" + from + "\" <" + System.getProperty("user.name") + "@"
                + InetAddress.getLocalHost().getHostName() + ">\r\n");
        out.print("To: " + to + "\r\n");
        out.print("Subject: " + subject + "\r\n");
        out.print("\r\n"); // blank line to end the list of headers

        // Now ask the user to enter the body of the message
        System.out.println("Enter the message. " + "End with a '.' on a line by itself.");
        // Read message line by line and send it out.
        String line;
        for (;;) {
            line = in.readLine();
            if ((line == null) || line.equals("."))
                break;
            out.print(line + "\r\n");
        }

        // Close (and flush) the stream to terminate the message
        out.close();
        // Tell the user it was successfully sent.
        System.out.println("Message sent.");
    } catch (Exception e) { // Handle any exceptions, print error message.
        System.err.println(e);
        System.err.println("Usage: java SendMail [<mailhost>]");
    }
}

From source file:de.phoenix.submissionpipeline.Core.java

public static void main(String[] args) {

    ObjectMapper mapper = new ObjectMapper();

    SubmissionTask task;//from  w  w w  .  java  2s .  c  o m
    try {
        task = mapper.readValue(System.in, SubmissionTask.class);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    try {
        CompileTask compileTask = new CompileTask(task);
        CharSequenceCompiler<Object> compiler = compileTask.compile();

        if (task.getTests().isEmpty()) {
            writeResult(mapper, new PhoenixSubmissionResult(SubmissionStatus.COMPILED, "Everything fine!"));
            return;
        }

        JUnitTask testTask = new JUnitTask(compiler, task);
        PhoenixSubmissionResult result = testTask.run();
        writeResult(mapper, result);
    } catch (UserSubmissionException e) {
        writeResult(mapper, new PhoenixSubmissionResult(SubmissionStatus.ERROR, e.getMessage()));
    }
}

From source file:Clima.Clima.java

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Scanner lea = new Scanner(System.in);

    int op;//  w ww  . j  a v  a 2  s .com

    do {
        System.out.println("----------\nMENU\n-----------");
        System.out.println("1- Ver todos los datos clima");
        System.out.println("2- Ver longuitud y Latitud");
        System.out.println("3- Temperatura minima y maxima");
        System.out.println("4- Humedad y Velocidad");
        System.out.println("Escoja Opcion: ");
        op = lea.nextInt();
        System.out.println("------------------------------------");
        System.out.println("Ingrase la ciudad que decea ver clima");
        System.out.println("-------------------------------------");
        String cuida = lea.next();
        System.out.println("--------------------------------------");

        switch (op) {
        case 1:
            try {

                String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida
                        + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55");
                JSONObject obj = new JSONObject(respuesta);
                double temp = obj.getJSONObject("main").getDouble("temp") - 273.15;
                double lon = obj.getJSONObject("coord").getDouble("lon");
                double lat = obj.getJSONObject("coord").getDouble("lat");
                double pressure = obj.getJSONObject("main").getDouble("pressure");
                double humidity = obj.getJSONObject("main").getDouble("humidity");
                double temp_min = obj.getJSONObject("main").getDouble("temp_min") - 273.15;
                double temp_max = obj.getJSONObject("main").getDouble("temp_max") - 273.15;
                double speed = obj.getJSONObject("wind").getDouble("speed");
                System.out.println("Los datos optenidos de " + cuida);
                System.out.println("***************************************1");
                System.out.println("La temperatura es: " + temp + " Celsius");
                System.out.println("longuitud  es: " + lon);
                System.out.println("Latitud es: " + lat);
                System.out.println("La presurisacion  es: " + pressure);
                System.out.println("La humedad es: " + humidity);
                System.out.println("La temperatura minima es: " + temp_min + " Celsius");
                System.out.println("La temperatura maxima es: " + temp_max + " Celsius");
                System.out.println("La velocidad es: " + speed);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Clima.main(null);
            break;
        case 2:
            try {

                String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida
                        + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55");
                JSONObject obj = new JSONObject(respuesta);
                double lon = obj.getJSONObject("coord").getDouble("lon");
                double lat = obj.getJSONObject("coord").getDouble("lat");
                System.out.println("Los datos optenidos de" + cuida + "son:");
                System.out.print("longuitud  es: " + lon);
                System.out.print("Latitud es: " + lat);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Clima.main(null);
            break;
        case 3:
            try {

                String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida
                        + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55");
                JSONObject obj = new JSONObject(respuesta);
                double temp_min = obj.getJSONObject("main").getDouble("temp_min") - 273.15;
                double temp_max = obj.getJSONObject("main").getDouble("temp_max") - 273.15;
                System.out.println("Los datos optenidos de" + cuida + "son:");
                System.out.print("La temperatura minima es: " + temp_min + " Celsius");
                System.out.print("La temperatura maxima es: " + temp_max + " Celsius");

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Clima.main(null);
            break;
        case 4:
            try {

                String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida
                        + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55");
                JSONObject obj = new JSONObject(respuesta);
                double humidity = obj.getJSONObject("main").getDouble("humidity");
                double speed = obj.getJSONObject("wind").getDouble("speed");
                System.out.println("Los datos optenidos de" + cuida + "son:");
                System.out.print("La humedad es: " + humidity);
                System.out.print("La velocidad es: " + speed);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Clima.main(null);
            break;

        }
    } while (op != 8);

}

From source file:FutureTest.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
    String directory = in.nextLine();
    System.out.print("Enter keyword (e.g. volatile): ");
    String keyword = in.nextLine();

    MatchCounter counter = new MatchCounter(new File(directory), keyword);
    FutureTask<Integer> task = new FutureTask<Integer>(counter);
    Thread t = new Thread(task);
    t.start();/*w  w  w . j  ava 2  s . c o  m*/
    try {
        System.out.println(task.get() + " matching files.");
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
}

From source file:com.blockhaus2000.csvviewer.CsvViewerMain.java

public static void main(final String[] args) {
    try (final CSVParser parser = new CSVParser(new InputStreamReader(System.in), CSVFormat.DEFAULT)) {
        final Table table = new Table();

        final Map<String, Integer> headerMap = parser.getHeaderMap();
        if (headerMap != null) {
            final TableRow headerRow = new TableRow();
            headerMap.keySet().forEach(headerData -> headerRow.addCell(new TableRowCell(headerData)));
            table.setHeaderRow(headerRow);
        }/*from   w  ww.  java  2  s  .  c o m*/

        final AtomicBoolean asHeader = new AtomicBoolean(headerMap == null);
        parser.getRecords().forEach(record -> {
            final TableRow row = new TableRow();
            record.forEach(rowData -> row.addCell(new TableRowCell(rowData)));
            if (asHeader.getAndSet(false)) {
                table.setHeaderRow(row);
            } else {
                table.addRow(row);
            }
        });

        System.out.println(table.getFormattedString());
    } catch (final IOException cause) {
        throw new RuntimeException("An error occurred whilst parsing stdin!", cause);
    }
}

From source file:RegExTest.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.println("Enter pattern: ");
    String patternString = in.nextLine();

    Pattern pattern = null;/*from  w w  w.java 2 s.  c o m*/
    try {
        pattern = Pattern.compile(patternString);
    } catch (PatternSyntaxException e) {
        System.out.println("Pattern syntax error");
        System.exit(1);
    }

    while (true) {
        System.out.println("Enter string to match: ");
        String input = in.nextLine();
        if (input == null || input.equals(""))
            return;
        Matcher matcher = pattern.matcher(input);
        if (matcher.matches()) {
            System.out.println("Match");
            int g = matcher.groupCount();
            if (g > 0) {
                for (int i = 0; i < input.length(); i++) {
                    for (int j = 1; j <= g; j++)
                        if (i == matcher.start(j))
                            System.out.print('(');
                    System.out.print(input.charAt(i));
                    for (int j = 1; j <= g; j++)
                        if (i + 1 == matcher.end(j))
                            System.out.print(')');
                }
                System.out.println();
            }
        } else
            System.out.println("No match");
    }
}

From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java

public static void main(String[] args) {
    try {/*  www. j  av a  2  s.c om*/
        final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        final String name = in.readLine();
        final List<RecordEntry> entries = new LinkedList<RecordEntry>();
        String line;
        while ((line = in.readLine()) != null) {
            final String[] parts = line.split("\\s+");
            final int length = Integer.parseInt(parts[0]);
            final int start = Integer.parseInt(parts[1]);
            final String entryName = parts[2];
            entries.add(new RecordEntry(length, start, entryName));
        }
        (new RecordClassMaker(name, entries)).execute();
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:org.springintegration.NotificationListener.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath:/META-INF/spring/integration/remote-monitor-context.xml");
    Gateway gw = ctx.getBean(Gateway.class);
    int cmd = 0;// w w w. j  a v a2 s.c o  m
    while (cmd != 'q') {
        cmd = System.in.read();
        gw.send((char) cmd);
    }
}

From source file:com.fizzed.rocker.bin.ConstantPoolMain.java

static public void main(String[] args) throws Exception {
    new ConstantPoolMain().run(args);

    System.out.println("About to exit app. Press any key to continue...");
    System.in.read();

    System.gc();//w ww .  ja v  a  2 s.  c o  m
    System.gc();
    System.gc();
    System.gc();

    System.out.println("-----------------------------");
    System.out.println("Just before exit");
    garbageCollectAndPrintMemory();
}

From source file:dataminning2.DataMinning2.java

/**
 * @param args the command line arguments
 *///w w w  .j  av  a  2s.  com
public static void main(String[] args) throws IOException {
    // here is the code to load the iris.csv data in an array 

    int ColumnCount = 0;
    int RowCount = 0;
    double[][] Dataarraytest;
    double[][] Dataarray;
    double[][] SVDS = null;
    double[][] SVDU = null;
    double[][] SVDV = null;
    System.out.println("Do you want to work with 1.att.csv or 2.iris.csv  ");
    InputStreamReader Datasetchoice = new InputStreamReader(System.in);
    BufferedReader BDatasetChoice = new BufferedReader(Datasetchoice);
    int Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
    String path = null;
    // LOadData LDobj=new LOadData();
    LOadData LDobj = new LOadData();
    TrainingSetDecomposition TestDataonj = new TrainingSetDecomposition();
    SVDDecomposition SVDobj = new SVDDecomposition();

    switch (Datasetchoicevalue) {
    case 1:
        path = "Datasets\\att.csv";
        ColumnCount = LDobj.ColumnCount(path);
        RowCount = LDobj.RowCount(path);
        Dataarray = LDobj.Datasetup(path, ColumnCount, RowCount);
        Dataarraytest = TestDataonj.Decomposition(RowCount, RowCount, 2, Dataarray);

        SVDS = SVDobj.DecompositionS(Dataarraytest);
        SVDU = SVDobj.DecompositionU(Dataarraytest);
        SVDV = SVDobj.DecompositionV(Dataarraytest);

        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "SVD");
        }

        KMeans_Ex4a Kmeanobj1 = new KMeans_Ex4a();
        double[][] KmeanData1 = Kmeanobj1.Main(SVDU);
        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSVKmean wcsvobj = new WriteCSVKmean();
            wcsvobj.writeCSVmethod(KmeanData1, "KMean");
        }

        Gui DBScanobj1 = new Gui();
        DBScanobj1.main(SVDU);

        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {

            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "DBScan");
        }

        break;

    case 2:
        path = "Datasets\\iris.csv";
        ColumnCount = LDobj.ColumnCount(path);
        RowCount = LDobj.RowCount(path);
        Dataarray = LDobj.Datasetup(path, ColumnCount, RowCount);
        Dataarraytest = TestDataonj.Decomposition(RowCount, 150, ColumnCount, Dataarray);

        SVDS = SVDobj.DecompositionS(Dataarraytest);
        SVDU = SVDobj.DecompositionU(Dataarraytest);
        SVDV = SVDobj.DecompositionV(Dataarraytest);
        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "SVD");
        }

        KMeans_Ex4a Kmeanobj = new KMeans_Ex4a();
        double[][] KmeanData = Kmeanobj.Main(SVDU);
        ssecalc distobj = new ssecalc();
        String output = distobj.calc(KmeanData);
        System.out.println(output);
        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSVKmean wcsvobj = new WriteCSVKmean();
            wcsvobj.writeCSVmethod(KmeanData, "KMean");
        }

        Gui DBScanobj = new Gui();
        DBScanobj.main(SVDU);

        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {

            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "DBScan");
        }

        break;
    }

}