Example usage for java.util Scanner nextLine

List of usage examples for java.util Scanner nextLine

Introduction

In this page you can find the example usage for java.util Scanner nextLine.

Prototype

public String nextLine() 

Source Link

Document

Advances this scanner past the current line and returns the input that was skipped.

Usage

From source file:hu.petabyte.redflags.engine.gear.indicator.hu.ContrDescCartellingIndicator.java

@Override
public void beforeSession() throws Exception {
    keywords.clear();//w  w w  .j a va  2  s  .c o  m
    Scanner s = new Scanner(new ClassPathResource(filename).getInputStream(), "UTF-8");
    while (s.hasNextLine()) {
        keywords.add(s.nextLine());
    }
    s.close();
    LOG.debug("Loaded {} expressions for cartelling", keywords.size());
    setWeight(0.5);
    super.beforeSession();
}

From source file:Phnbk.java

private void process(Connection connection, Statement statement) throws SQLException, Exception {
    Scanner sc = new Scanner(System.in);
    System.out.println("Search by : name/number?");
    String choice = sc.nextLine();
    System.out.println("Enter the " + choice + " : ");
    String param = sc.nextLine();

    if (choice.toLowerCase().equalsIgnoreCase("name")) {
        detailsName(statement, param, connection);
    } else if (choice.toLowerCase().equalsIgnoreCase("number")) {
        detailsNumber(statement, param, connection);
    } else {/*  w  w w. j a  v  a  2  s . co  m*/
        System.out.println("Invalid Choice!!");
    }

    //MethodBank.dropDataBase(statement, dataBaseName);
    //closeConnection(connection);
    //closeStatement(statement);

}

From source file:net.bashtech.geobot.BotManager.java

public static String postRemoteDataTwitch(String urlString, String postData, int krakenVersion) {
    URL url;/*from  www . jav  a2 s  . c  o  m*/
    HttpURLConnection conn;

    try {
        url = new URL(urlString);

        conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");

        conn.setFixedLengthStreamingMode(postData.getBytes().length);
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Accept", "application/vnd.twitchtv.v" + krakenVersion + "+json");
        conn.setRequestProperty("Authorization", "OAuth " + BotManager.getInstance().krakenOAuthToken);
        conn.setRequestProperty("Client-ID", BotManager.getInstance().krakenClientID);
        // conn.setConnectTimeout(5 * 1000);
        // conn.setReadTimeout(5 * 1000);

        PrintWriter out = new PrintWriter(conn.getOutputStream());
        out.print(postData);
        out.close();

        String response = "";

        Scanner inStream = new Scanner(conn.getInputStream());

        while (inStream.hasNextLine())
            response += (inStream.nextLine());

        inStream.close();
        return response;

    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return "";
}

From source file:net.bashtech.geobot.BotManager.java

public static String postRemoteDataStrawpoll(String urlString) {

    String line = "";
    try {// w  w  w.  j  av  a  2 s .  c  o  m
        HttpURLConnection c = (HttpURLConnection) (new URL("http://strawpoll.me/api/v2/polls")
                .openConnection());

        c.setRequestMethod("POST");
        c.setRequestProperty("Content-Type", "application/json");
        c.setRequestProperty("User-Agent", "CB2");

        c.setDoOutput(true);
        c.setDoInput(true);
        c.setUseCaches(false);

        String queryString = urlString;

        c.setRequestProperty("Content-Length", Integer.toString(queryString.length()));

        DataOutputStream wr = new DataOutputStream(c.getOutputStream());
        wr.writeBytes(queryString);

        wr.flush();
        wr.close();

        Scanner inStream = new Scanner(c.getInputStream());

        while (inStream.hasNextLine())
            line += (inStream.nextLine());

        inStream.close();
        System.out.println(line);
        try {
            JSONParser parser = new JSONParser();
            Object obj = parser.parse(line);
            JSONObject jsonObject = (JSONObject) obj;
            line = (Long) jsonObject.get("id") + "";

        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return line;
}

From source file:BlockingQueueTest.java

/**
 * Searches a file for a given keyword and prints all matching lines.
 * @param file the file to search/*from  ww w . j  a v a 2  s .c o  m*/
 */
public void search(File file) throws IOException {
    Scanner in = new Scanner(new FileInputStream(file));
    int lineNumber = 0;
    while (in.hasNextLine()) {
        lineNumber++;
        String line = in.nextLine();
        if (line.contains(keyword))
            System.out.printf("%s:%d:%s%n", file.getPath(), lineNumber, line);
    }
    in.close();
}

From source file:ezbake.deployer.publishers.local.BaseLocalPublisher.java

private void inheritIO(final InputStream src, final PrintStream dest) {
    new Thread(new Runnable() {
        public void run() {
            Scanner sc = new Scanner(src);
            while (sc.hasNextLine()) {
                dest.println(sc.nextLine());
            }/*from   w  w  w .j  a  v a2s .  co  m*/
        }
    }).start();
}

From source file:hammingcode.HammingCode.java

ArrayList<String> readFile(String filename) throws FileNotFoundException {
    Scanner input = new Scanner(new File(filename));
    ArrayList<String> inputList = new ArrayList();
    while (input.hasNext()) {
        inputList.add(input.nextLine());
    }/*  w w w . jav  a  2s . com*/
    return inputList;
}

From source file:net.bashtech.geobot.BotManager.java

public static String postCoebotConfig(String postData, String channel) {
    if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) {
        URL url;//from   ww  w.j  av  a  2  s. c  om
        HttpURLConnection conn;

        try {
            url = new URL("http://coebot.tv/api/v1/channel/update/config/" + channel.toLowerCase() + "$"
                    + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick);

            conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("User-Agent", "CoeBot");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length));

            // conn.setConnectTimeout(5 * 1000);
            // conn.setReadTimeout(5 * 1000);

            PrintWriter out = new PrintWriter(conn.getOutputStream());
            out.print(postData);
            out.close();

            String response = "";

            Scanner inStream = new Scanner(conn.getInputStream());

            while (inStream.hasNextLine())
                response += (inStream.nextLine());

            inStream.close();
            return response;

        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        return "";
    } else
        return "";
}

From source file:net.bashtech.geobot.BotManager.java

public static String postCoebotVars(String postData, String requestURL) {
    if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) {
        URL url;/*ww  w  . j  a  v a 2 s . c o  m*/
        HttpURLConnection conn;

        try {
            url = new URL(requestURL + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$"
                    + BotManager.getInstance().nick);

            conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("User-Agent", "CoeBot");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length));

            // conn.setConnectTimeout(5 * 1000);
            // conn.setReadTimeout(5 * 1000);

            PrintWriter out = new PrintWriter(conn.getOutputStream());
            out.print(postData);
            out.close();

            String response = "";

            Scanner inStream = new Scanner(conn.getInputStream());

            while (inStream.hasNextLine())
                response += (inStream.nextLine());

            inStream.close();
            return response;

        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        return "";
    } else
        return "";
}

From source file:ThreadPoolTest.java

/**
 * Searches a file for a given keyword.//w w  w  .  j  a  v a  2  s.c om
 * 
 * @param file
 *          the file to search
 * @return true if the keyword is contained in the file
 */
public boolean search(File file) {
    try {
        Scanner in = new Scanner(new FileInputStream(file));
        boolean found = false;
        while (!found && in.hasNextLine()) {
            String line = in.nextLine();
            if (line.contains(keyword))
                found = true;
        }
        in.close();
        return found;
    } catch (IOException e) {
        return false;
    }
}