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

public static void main(String[] args) throws Exception {
    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();

    ExecutorService pool = Executors.newCachedThreadPool();

    MatchCounter counter = new MatchCounter(new File(directory), keyword, pool);
    Future<Integer> result = pool.submit(counter);

    try {/*  w  w w  .  jav a 2 s  .  com*/
        System.out.println(result.get() + " matching files.");
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
    pool.shutdown();

    int largestPoolSize = ((ThreadPoolExecutor) pool).getLargestPoolSize();
    System.out.println("largest pool size=" + largestPoolSize);
}

From source file:io.github.mikesaelim.arxivoaiharvester.CommandLineInterface.java

public static void main(String[] args) throws InterruptedException {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    ArxivOAIHarvester harvester = new ArxivOAIHarvester(httpClient);
    Scanner scanner = new Scanner(System.in);

    System.out.println();/* w  w w  .  j  a  v a2s .c  o  m*/
    System.out.println("Welcome to the command line interface of the arXiv OAI Harvester!");
    System.out.println(
            "This program sends one query to the arXiv OAI repository and prints the results to STDOUT.");
    System.out.println("It uses the default settings for query retries.");
    System.out.println();
    System.out.println("Which verb would you like to use?");
    System.out.println("    1) GetRecord - retrieve a single record");
    System.out.println("    2) ListRecords - retrieve a range of records");
    System.out.println("    or enter anything else to quit.");

    switch (scanner.nextLine().trim()) {
    case "1":
        handleGetRecordRequest(scanner, harvester);
        break;
    case "2":
        handleListRecordsRequest(scanner, harvester);
    }
}

From source file:com.dinstone.jrpc.NamespaceHandlerTest.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "application-context-sample.xml");

    HelloService service = (HelloService) applicationContext.getBean("rhsv1");
    try {//  ww  w.jav  a 2s.  c  om
        testHot(service);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        testSend1k(service);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.in.read();
    } catch (IOException e) {
    }

    applicationContext.close();
}

From source file:com.alibaba.dubbo.examples.annotation.AnnotationConsumer.java

public static void main(String[] args) throws Exception {
    String config = AnnotationConsumer.class.getPackage().getName().replace('.', '/')
            + "/annotation-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//w w  w.ja v a 2 s .  com
    final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
    System.in.read();
}

From source file:ReflectionTest.java

public static void main(String[] args) {
    // read class name from command line args or user input
    String name;/*from  www.  j  a  v a  2s .c om*/
    if (args.length > 0)
        name = args[0];
    else {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter class name (e.g. java.util.Date): ");
        name = in.next();
    }

    try {
        // print class name and superclass name (if != Object)
        Class cl = Class.forName(name);
        Class supercl = cl.getSuperclass();
        String modifiers = Modifier.toString(cl.getModifiers());
        if (modifiers.length() > 0)
            System.out.print(modifiers + " ");
        System.out.print("class " + name);
        if (supercl != null && supercl != Object.class)
            System.out.print(" extends " + supercl.getName());

        System.out.print("\n{\n");
        printConstructors(cl);
        System.out.println();
        printMethods(cl);
        System.out.println();
        printFields(cl);
        System.out.println("}");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.exit(0);
}

From source file:id3Crawler.java

public static void main(String[] args) throws IOException {

    //Input for the directory to be searched.
    System.out.println("Please enter a directory: ");
    Scanner scanner = new Scanner(System.in);
    String input = scanner.nextLine();

    //Start a timer to calculate runtime
    startTime = System.currentTimeMillis();

    System.out.println("Starting scan...");

    //Files for output
    PrintWriter pw1 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Song.txt"));
    PrintWriter pw2 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Artist.txt"));
    PrintWriter pw3 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Album.txt"));
    PrintWriter pw4 = new PrintWriter(
            new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/PerformedBy.txt"));
    PrintWriter pw5 = new PrintWriter(
            new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/TrackOf.txt"));
    PrintWriter pw6 = new PrintWriter(
            new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/CreatedBy.txt"));

    //This is used for creating IDs for artists, songs, albums.
    int idCounter = 0;

    //This is used to prevent duplicate artists
    String previousArtist = " ";
    String currentArtist;/*from   w w w . j a  va  2  s .com*/
    int artistID = 0;

    //This is used to prevent duplicate albums
    String previousAlbum = " ";
    String currentAlbum;
    int albumID = 0;

    //This array holds valid extensions to iterate through
    String[] extensions = new String[] { "mp3" };

    //iterate through all files in a directory
    Iterator<File> it = FileUtils.iterateFiles(new File(input), extensions, true);
    while (it.hasNext()) {

        //open the next file
        File file = it.next();

        //instantiate an mp3file object with the opened file
        MP3 song = GetMP3(file);

        //pass the song through SongInfo and return the required information
        SongInfo info = new SongInfo(song);

        //This is used to prevent duplicate artists/albums
        currentArtist = info.getArtistInfo();
        currentAlbum = info.getAlbumInfo();

        //Append the song information to the end of a text file
        pw1.println(idCounter + "\t" + info.getTitleInfo());

        //This prevents duplicates of artists
        if (!(currentArtist.equals(previousArtist))) {
            pw2.println(idCounter + "\t" + info.getArtistInfo());
            previousArtist = currentArtist;
            artistID = idCounter;
        }

        //This prevents duplicates of albums
        if (!(currentAlbum.equals(previousAlbum))) {
            pw3.println(idCounter + "\t" + info.getAlbumInfo());
            previousAlbum = currentAlbum;
            albumID = idCounter;

            //This formats the IDs for a "CreatedBy" relationship table
            pw6.println(artistID + "\t" + albumID);
        }

        //This formats the IDs for a "PerformedBy" relationship table
        pw4.println(idCounter + "\t" + artistID);

        //This formats the IDs for a "TrackOf" relationship table
        pw5.println(idCounter + "\t" + albumID);

        idCounter++;
        songCounter++;

    }
    scanner.close();
    pw1.close();
    pw2.close();
    pw3.close();
    pw4.close();
    pw5.close();
    pw6.close();

    System.out.println("Scan took " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds to scan "
            + songCounter + " items!");

}

From source file:com.alibaba.dubbo.examples.version.VersionConsumer.java

public static void main(String[] args) throws Exception {
    String config = VersionConsumer.class.getPackage().getName().replace('.', '/') + "/version-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();// ww w.j av a 2 s .co  m
    VersionService versionService = (VersionService) context.getBean("versionService");
    for (int i = 0; i < 10000; i++) {
        String hello = versionService.sayHello("world");
        System.out.println(hello);
        Thread.sleep(2000);
    }
    System.in.read();
}

From source file:com.grayfox.server.Program.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            MainConfig.class)) {
        new Program().run(applicationContext, new Scanner(System.in));
    } catch (Exception ex) {
        LOGGER.error("Error during execution", ex);
    }/*from   w  w w .ja  va 2s.co m*/
}

From source file:com.richard.memorystore.udp.UDPServer.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*from  ww w .  j a v  a 2s . c o  m*/
 */
public static void main(String[] args) {

    final Scanner scanner = new Scanner(System.in);

    System.out.println("\n========================================================="
            + "\n                                                         "
            + "\n    Welcome to the Spring Integration                    "
            + "\n          TCP-Client-Server Sample!                      "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://www.springintegration.org/                    "
            + "\n                                                         "
            + "\n=========================================================");

    final GenericXmlApplicationContext context = UDPServer.setupContext();
    //      final SimpleGateway gateway = context.getBean(SimpleGateway.class);
    //      final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class);

    System.out.print("Waiting for server to accept connections...");
    //TestingUtilities.waitListening(crLfServer, 10000L);
    System.out.println("running.\n\n");

    System.out.println("Please enter some text and press <enter>: ");
    System.out.println("\tNote:");
    System.out.println("\t- Entering FAIL will create an exception");
    System.out.println("\t- Entering q will quit the application");
    System.out.print("\n");
    System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests.");
    //System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }
        //         else {
        //            final String result = gateway.send(input);
        //            System.out.println(result);
        //         }
    }

    System.out.println("Exiting application...bye.");
    System.exit(0);

}

From source file:eu.riscoss.datacollectors.ExampleDataCollector.java

public static void main(String[] args) throws Exception {
    JSONObject input;//from   w w w  . j av  a2 s  .c o  m
    if (args.length > 0 && "--stdin-conf".equals(args[args.length - 1])) {
        String stdin = IOUtils.toString(System.in, "UTF-8");
        input = new JSONObject(stdin);
    } else {
        input = testInput();
        System.out.println("using " + input + " as test configuration.");
        System.out.println("In production, use --stdin-conf and pass configuration to stdin");
    }

    JSONObject outObj = new JSONObject();
    outObj.put("id", COLLECTOR_ID);
    outObj.put("type", COLLECTOR_DATATYPE);
    outObj.put("target", input.getString("riscoss_targetName"));
    outObj.put("value", getData(input));

    JSONArray outArray = new JSONArray();
    outArray.put(outObj);
    System.out.println("-----BEGIN RISK DATA-----");
    System.out.println(outArray.toString());
    System.out.println("-----END RISK DATA-----");
}