Example usage for java.util Scanner hasNextLine

List of usage examples for java.util Scanner hasNextLine

Introduction

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

Prototype

public boolean hasNextLine() 

Source Link

Document

Returns true if there is another line in the input of this scanner.

Usage

From source file:de.rub.syssec.saaf.analysis.steps.hash.SSDeep.java

protected static String calculateFuzzyHash(File f) throws IOException {
    String hash = null;/*w w w .ja  v a  2 s.c  o m*/

    if (SSDEEP_PATH != null) {
        ProcessBuilder pb = new ProcessBuilder(SSDEEP_PATH, f.getAbsolutePath());
        Process proc;
        Scanner in = null;
        try {
            proc = pb.start();
            // Start reading from the program
            in = new Scanner(proc.getInputStream());
            while (in.hasNextLine()) {
                hash = in.nextLine();
            }
            if (hash != null)
                return hash.substring(0, hash.lastIndexOf(","));
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (Exception ignored) {
            }
        }
    } else {
        LOGGER.warn("exec_ssdeep could not be found in saaf.conf");
    }
    return "";
}

From source file:com.easarrive.aws.plugins.common.util.SNSUtil.java

public static StringBuilder getHttpRequestContent(InputStream inputStream) {
    Scanner scan = null;
    StringBuilder builder = new StringBuilder();
    try {//  w w w .  j ava2  s .  c om
        scan = new Scanner(inputStream);
        while (scan.hasNextLine()) {
            builder.append(scan.nextLine());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtil.close(scan);
    }
    return builder;
}

From source file:org.mrgeo.cmd.generatekeys.GenerateKeys.java

private static List<Long> readRandomKeys(File file) throws FileNotFoundException {
    List<Long> keys = new ArrayList<Long>();
    java.util.Scanner in = new java.util.Scanner(new BufferedReader(new FileReader(file)));
    while (in.hasNextLine()) {
        keys.add(Long.valueOf(in.nextLine()));
    }//  w w w .j  a va 2  s.  c  o  m
    in.close();
    return keys;
}

From source file:com.mirth.connect.server.util.DatabaseUtil.java

public static List<String> joinSqlStatements(Collection<String> scripts) {
    List<String> scriptList = new ArrayList<String>();

    for (String script : scripts) {
        script = script.trim();//from  ww w. ja  va2 s  . co m
        StringBuilder sb = new StringBuilder();
        boolean blankLine = false;
        Scanner scanner = new Scanner(script);

        while (scanner.hasNextLine()) {
            String temp = scanner.nextLine();

            if (temp.trim().length() > 0) {
                sb.append(temp + " ");
            } else {
                blankLine = true;
            }

            if (blankLine || !scanner.hasNextLine()) {
                scriptList.add(sb.toString().trim());
                blankLine = false;
                sb.delete(0, sb.length());
            }
        }
    }

    return scriptList;
}

From source file:net.henryco.opalette.api.utils.Utils.java

public static String getLineFromString(String line, int n) {
    String returnString = "";
    Scanner scanner = new Scanner(line);
    int i = 0;//from ww w. j  a  v a2 s  . c  om
    while (scanner.hasNextLine()) {
        returnString = scanner.nextLine();
        if (i++ == n)
            break;
    }
    scanner.close();
    return returnString;
}

From source file:at.tuwien.aic.Main.java

private static String getNonEmptyString(String msg, String defaultValue) {
    Scanner scanner = new Scanner(System.in);
    String ret = defaultValue;//  ww w . j  a  v a2  s .  c o  m

    print(msg, ret);

    while (scanner.hasNextLine()) {
        ret = scanner.nextLine();

        if (!ret.equals("")) {
            break;
        }

        print(msg, ret);
    }

    return ret;
}

From source file:org.bibsonomy.util.tex.TexDecode.java

/**
 * parse the file containing the mappings of unicode characters to latex
 * macros and store it in texMap./*ww  w.  j  a  va 2 s  . c o m*/
 */
private static final void loadMapFile() {
    Scanner scanner = new Scanner(
            TexDecode.class.getClassLoader().getResourceAsStream(LATEXMACRO_UNICODECHAR_MAP_FILENAME), "UTF-8");
    String line;
    String[] parts;
    while (scanner.hasNextLine()) {
        line = scanner.nextLine();
        parts = line.split(LATEXMACRO_UNICODECHAR_MAP_DELIM);
        // convert hex representation into unicode string
        texMap.put(parts[1].trim(), String.valueOf(Character.toChars(Integer.parseInt(parts[0].trim(), 16))));
        LOGGER.debug("added new mapping " + parts[1].trim() + " -> " + texMap.get(parts[1].trim()));
    }

}

From source file:ec.edu.ucuenca.dcc.sld.HttpUtils.java

public static synchronized String Http2_(String s, Map<String, String> mp) throws SQLException, IOException {
    String resp = "";
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(s);
    method.getParams().setContentCharset("utf-8");
    //Add any parameter if u want to send it with Post req.
    for (Entry<String, String> mcc : mp.entrySet()) {
        method.addParameter(mcc.getKey(), mcc.getValue());
    }//from   w  w  w.ja  va2  s  .com
    int statusCode = client.executeMethod(method);
    if (statusCode != -1) {
        InputStream in = method.getResponseBodyAsStream();
        final Scanner reader = new Scanner(in, "UTF-8");
        while (reader.hasNextLine()) {
            final String line = reader.nextLine();
            resp += line + "\n";
        }
        reader.close();
    }
    return resp;
}

From source file:org.dkpro.tc.ml.crfsuite.task.CRFSuiteTestTask.java

public static StringBuilder captureProcessOutput(Process aProcess) {
    InputStream src = aProcess.getInputStream();
    Scanner sc = new Scanner(src, "utf-8");
    StringBuilder dest = new StringBuilder();
    while (sc.hasNextLine()) {
        String l = sc.nextLine();
        dest.append(l + "\n");
    }/*from   w ww .j a va 2 s .  c o m*/
    sc.close();
    return dest;
}

From source file:com.mirth.connect.server.util.DatabaseUtil.java

public static void executeScript(String script, boolean ignoreErrors) throws Exception {
    SqlSessionManager sqlSessionManger = SqlConfig.getSqlSessionManager();

    Connection conn = null;// ww w  .  ja v  a2s .  com
    ResultSet resultSet = null;
    Statement statement = null;

    try {
        sqlSessionManger.startManagedSession();
        conn = sqlSessionManger.getConnection();

        /*
         * Set auto commit to false or an exception will be thrown when trying to rollback
         */
        conn.setAutoCommit(false);

        statement = conn.createStatement();

        Scanner s = new Scanner(script);

        while (s.hasNextLine()) {
            StringBuilder sb = new StringBuilder();
            boolean blankLine = false;

            while (s.hasNextLine() && !blankLine) {
                String temp = s.nextLine();

                if (temp.trim().length() > 0)
                    sb.append(temp + " ");
                else
                    blankLine = true;
            }

            // Trim ending semicolons so Oracle doesn't throw
            // "java.sql.SQLException: ORA-00911: invalid character"
            String statementString = StringUtils.removeEnd(sb.toString().trim(), ";");

            if (statementString.length() > 0) {
                try {
                    statement.execute(statementString);
                    conn.commit();
                } catch (SQLException se) {
                    if (!ignoreErrors) {
                        throw se;
                    } else {
                        logger.error("Error was encountered and ignored while executing statement: "
                                + statementString, se);
                        conn.rollback();
                    }
                }
            }
        }

    } catch (Exception e) {
        throw new Exception(e);
    } finally {
        DbUtils.closeQuietly(statement);
        DbUtils.closeQuietly(resultSet);
        DbUtils.closeQuietly(conn);
        sqlSessionManger.close();
    }
}