Example usage for java.io BufferedReader readLine

List of usage examples for java.io BufferedReader readLine

Introduction

In this page you can find the example usage for java.io BufferedReader readLine.

Prototype

public String readLine() throws IOException 

Source Link

Document

Reads a line of text.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String text = "q";
    while (true) {
        System.out.print("Please type a message (Q/q to quit) and press enter:");
        text = br.readLine();
        if (text.equalsIgnoreCase("q")) {
            System.out.println("We have  decided to exit  the   program");
            break;
        } else {/* w  w  w . j  a v  a 2s.  c  o  m*/
            System.out.println("We typed: " + text);
        }
    }
}

From source file:org.openplans.delayfeeder.LoadFeeds.java

public static void main(String args[]) throws HibernateException, IOException {
    if (args.length != 1) {
        System.out.println("expected one argument: the path to a csv of agency,route,url");
    }/*from  w  w w . ja v a2 s. c  o m*/
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.loadBeanDefinitions("org/openplans/delayfeeder/application-context.xml");
    xmlReader.loadBeanDefinitions("data-sources.xml");

    SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");

    Session session = sessionFactory.getCurrentSession();
    Transaction tx = session.beginTransaction();

    FileReader fileReader = new FileReader(new File(args[0]));
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    while (bufferedReader.ready()) {
        String line = bufferedReader.readLine().trim();
        if (line.startsWith("#")) {
            continue;
        }
        if (line.length() < 3) {
            //blank or otherwise broken line
            continue;
        }

        String[] parts = line.split(",");
        String agency = parts[0];
        String route = parts[1];
        String url = parts[2];
        Query query = session.createQuery("from RouteFeed where agency = :agency and route = :route");
        query.setParameter("agency", agency);
        query.setParameter("route", route);
        @SuppressWarnings("rawtypes")
        List list = query.list();
        RouteFeed feed;
        if (list.size() == 0) {
            feed = new RouteFeed();
            feed.agency = agency;
            feed.route = route;
            feed.lastEntry = new GregorianCalendar();
        } else {
            feed = (RouteFeed) list.get(0);
        }
        if (!url.equals(feed.url)) {
            feed.url = url;
            feed.lastEntry.setTimeInMillis(0);
        }
        session.saveOrUpdate(feed);
    }
    tx.commit();
}

From source file:UseTrim.java

public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str;/*  w w  w  .  j  a va2s  . co m*/

    System.out.println("Enter 'stop' to quit.");
    System.out.println("Enter letter: ");
    do {
        str = br.readLine();
        str = str.trim();

        if (str.equals("I"))
            System.out.println("I");
        else if (str.equals("M"))
            System.out.println("M");
        else if (str.equals("C"))
            System.out.println("C.");
        else if (str.equals("W"))
            System.out.println("W");
    } while (!str.equals("stop"));
}

From source file:mx.com.pixup.portal.demo.DemoDisqueraDelete.java

public static void main(String[] args) {
    System.out.println("BIENVENIDO A PIXUP");
    System.out.println("Mantenimiento catlogo disquera");
    System.out.println("Inserte el nombre de la disquera a eliminar: ");

    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    Connection connection = null;
    Statement statement = null;//w ww .  j  a  v  a 2  s  .co  m
    try {
        String nombreDisquera = br.readLine();
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("admin");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/pixup");

        connection = dataSource.getConnection();
        statement = connection.createStatement();

        String sql = "delete from disquera where nombre = '" + nombreDisquera + "'";

        statement.execute(sql);

        System.out.println("Disquera: " + nombreDisquera + " eliminada con xito");

    } catch (Exception e) {
        System.out.println("Error en el sistema, intente ms tarde!!");
    } finally {
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception e) {
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:cc.twittertools.util.ExtractSubcollection.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory")
            .create(COLLECTION_OPTION));
    options.addOption(/*  ww  w  .  ja v  a  2s  .c o m*/
            OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractSubcollection.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    LongOpenHashSet tweetids = new LongOpenHashSet();
    File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION));
    if (!tweetidsFile.exists()) {
        System.err.println("Error: " + tweetidsFile + " does not exist!");
        System.exit(-1);
    }
    LOG.info("Reading tweetids from " + tweetidsFile);

    FileInputStream fin = new FileInputStream(tweetidsFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));

    String s;
    while ((s = br.readLine()) != null) {
        tweetids.add(Long.parseLong(s));
    }
    br.close();
    fin.close();
    LOG.info("Read " + tweetids.size() + " tweetids.");

    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    StatusStream stream = new JsonStatusCorpusReader(file);
    Status status;
    while ((status = stream.next()) != null) {
        if (tweetids.contains(status.getId())) {
            out.println(status.getJsonObject().toString());
        }
    }
    stream.close();
    out.close();
}

From source file:RestGetClient.java

public static void main(String[] args) throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getRequest = new HttpGet("http://localhost:10080/example/json/product/get");
    getRequest.addHeader("accept", "application/json");

    HttpResponse response = httpClient.execute(getRequest);

    //if (response.getStatusLine().getStatusCode() != 200) {
    //   throw new RuntimeException("Failed : HTTP error code : "
    //      + response.getStatusLine().getStatusCode());
    //}//from w  w  w. ja v a2s  .c o  m

    BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

    String output;
    System.out.println("Output from Server .... \n");
    while ((output = br.readLine()) != null) {
        System.out.println(output);
    }

    httpClient.getConnectionManager().shutdown();
}

From source file:com.test.restdev.simpleRestClient.java

public static void main(String[] args) throws ClientProtocolException, IOException {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://localhost:8080/restdev/resources/developers/rafi-kokos");
    HttpGet request1 = new HttpGet("http://localhost:8081/restdev/resources/developers/rafi-kokos");
    HttpGet request2 = new HttpGet("http://localhost:8082/restdev/resources/developers/rafi-kokos");
    HttpResponse response;/*from w  ww.  j  a va2 s.co m*/
    for (int i = 0; i < 10; i++) {
        if (i % 3 == 0) {
            response = client.execute(request);
            System.out.println("If (i%3==0) -> call no. " + i + " to uri:" + request.getURI());
        } else if (i % 3 == 1) {
            response = client.execute(request1);
            System.out.println("If (i%3==1) -> call no. " + i + " to uri:" + request1.getURI());
        } else if (i % 3 == 2) {
            response = client.execute(request2);
            System.out.println("If (i%3==2) -> call no. " + i + " to uri:" + request2.getURI());
        } else {
            response = client.execute(request);
            System.out.println("Else -> call no. " + i + " to uri:" + request.getURI());
        }
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        System.out.println("call no. " + i);
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
        }
    }

}

From source file:TabFilter.java

public static void main(String args[]) throws Exception {
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);

    FileWriter fw = new FileWriter(args[1]);
    BufferedWriter bw = new BufferedWriter(fw);

    // Convert tab to space characters
    String s;/*  www.  j  av a 2 s.c o m*/
    while ((s = br.readLine()) != null) {
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '\t')
                c = ' ';
            bw.write(c);
        }
    }

    bw.flush();
    fr.close();
    fw.close();
}

From source file:Main.java

License:asdf

public static void main(String[] arges) throws Exception {

    InetAddress addr = InetAddress.getByName(null);
    Socket sk = new Socket(addr, 8888);
    BufferedReader in = new BufferedReader(new InputStreamReader(sk.getInputStream()));
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sk.getOutputStream())), true);
    out.println("asdf");
    System.out.println(in.readLine());
}

From source file:edu.msu.cme.rdp.graph.sandbox.BloomFilterInterrogator.java

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("USAGE: BloomFilterStats <bloom_filter>");
        System.exit(1);/*from   w  w w. j ava  2s.  com*/
    }

    File bloomFile = new File(args[0]);

    ObjectInputStream ois = ois = new ObjectInputStream(
            new BufferedInputStream(new FileInputStream(bloomFile)));
    BloomFilter filter = (BloomFilter) ois.readObject();
    ois.close();

    printStats(filter, System.out);

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String line;
    CodonWalker walker = null;
    while ((line = reader.readLine()) != null) {
        char[] kmer = line.toCharArray();
        System.out.print(line + "\t");
        try {
            walker = filter.new RightCodonFacade(kmer);
            walker.jumpTo(kmer);
            System.out.print("present");
        } catch (Exception e) {
            System.out.print("not present\t" + e.getMessage());
        }
        System.out.println();
    }
}