Example usage for java.io LineNumberReader LineNumberReader

List of usage examples for java.io LineNumberReader LineNumberReader

Introduction

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

Prototype

public LineNumberReader(Reader in) 

Source Link

Document

Create a new line-numbering reader, using the default input-buffer size.

Usage

From source file:Main.java

public static int getLineCount(String path) {
    LineNumberReader lnr = null;//from w w w .j  a  va2  s . com
    try {
        lnr = new LineNumberReader(new FileReader(new File(path)));
        lnr.skip(Long.MAX_VALUE);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (lnr == null)
        return 0;
    return lnr.getLineNumber();
}

From source file:Main.java

public static String getMac() {
    String result = "";
    try {//from   www. j a v  a  2  s  . c o  m

        Process process = Runtime.getRuntime().exec("ipconfig /all");

        InputStreamReader ir = new InputStreamReader(process.getInputStream());

        LineNumberReader input = new LineNumberReader(ir);

        String line;

        while ((line = input.readLine()) != null)

            if (line.indexOf("Physical Address") > 0) {

                String MACAddr = line.substring(line.indexOf("-") - 2);

                result = MACAddr;

            }

    } catch (java.io.IOException e) {

        System.err.println("IOException " + e.getMessage());

    }
    return result;
}

From source file:Main.java

public static String getMac() {
    String macAdress = null;/*from   www  .  j  av  a2s . c  o  m*/
    String str = "";
    try {
        Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address ");
        InputStreamReader ir = new InputStreamReader(pp.getInputStream());
        LineNumberReader input = new LineNumberReader(ir);
        for (; null != str;) {
            str = input.readLine();
            if (str != null) {
                macAdress = str.trim();
                break;
            }
        }
        ir.close();
        input.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return macAdress;
}

From source file:edu.stanford.muse.email.MboxEmailStore.java

public static void main(String args[]) throws MessagingException, IOException {
    LineNumberReader lnr = new LineNumberReader(new BufferedReader(
            new InputStreamReader(new FileInputStream("/Users/hangal/Local Folders/gmail-sent"))));
    int count = 0;
    while (true) {
        String line = lnr.readLine();
        if (line == null)
            break;
        if (line.startsWith("From "))
            count++;//from w w  w  . java  2 s  .  c om
    }
    System.out.println(count + " messages found");
}

From source file:Main.java

private static String getMacAddress() {
    String macSerial = null;//from   ww  w  .  ja  v a2 s .  co  m
    String str = "";
    try {
        Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
        InputStreamReader ir = new InputStreamReader(pp.getInputStream());
        LineNumberReader input = new LineNumberReader(ir);

        for (; null != str;) {
            str = input.readLine();
            if (str != null) {
                str = str.trim();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < str.length(); i++) {
                    if (str.charAt(i) != ':') {
                        sb.append(str.charAt(i));
                    }
                }
                macSerial = sb.toString();
                break;
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return macSerial;
}

From source file:Main.java

public static String getRandomNumByLine(int i) {
    File file = new File("/storage/emulated/0/uber_random");
    LineNumberReader lineNumberReader = null;
    StringBuilder builder = new StringBuilder();
    try {//from w ww  . j  av  a  2  s. c  om
        if (file.exists()) {
            lineNumberReader = new LineNumberReader(new FileReader(file));
            String tmp = null;
            while ((tmp = lineNumberReader.readLine()) != null) {
                builder.append(tmp + "\n");
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (null != lineNumberReader) {
            try {
                lineNumberReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    String fileString = builder.toString();
    Log.d("TAG", "Read num is --->" + fileString);
    String[] split = fileString.split("\\n");
    if (split != null && (split.length >= i)) {
        String value = split[i];
        Log.d("TAG", "Read sub is --->" + value);
        return value;
    }
    return null;
}

From source file:Main.java

public static String getMac() {
    String mac = null;/*ww  w.j a  v a 2 s .c  om*/
    String macSerial = null;
    String str = "";
    try {
        Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
        //            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/eth0/address");
        InputStreamReader ir = new InputStreamReader(pp.getInputStream());
        LineNumberReader input = new LineNumberReader(ir);

        for (; null != str;) {
            str = input.readLine();
            if (str != null) {
                macSerial = str.trim();
                break;
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    if (macSerial != null) {
        macSerial = macSerial.replace(":", "");
        macSerial = macSerial.replace("a", "A");
        macSerial = macSerial.replace("b", "B");
        macSerial = macSerial.replace("c", "C");
        macSerial = macSerial.replace("d", "D");
        macSerial = macSerial.replace("e", "E");
        mac = macSerial.replace("f", "F");
    }

    return mac;

}

From source file:Main.java

/**
 * Reads the first non-empty line from a file.
 *
 * @param file the file from which the line is to be read. This argument
 *   cannot be {@code null}./*from  w w w  .j av  a2s.co  m*/
 * @return the first non-empty line in the given file or {@code null} if
 *   there is no such line in the specified file
 *
 * @throws IOException thrown if there was an error while reading the
 *   specified file (e.g.: it does not exist)
 */
private static String readFirstLine(Path file) throws IOException {
    try (InputStream input = Files.newInputStream(file)) {
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(input, DEFAULT_CHARSET));
        String line = reader.readLine();
        while (line != null) {
            line = line.trim();
            if (!line.isEmpty()) {
                return line;
            }
            line = reader.readLine();
        }
    }

    return null;
}

From source file:Main.java

public static List<String> splitLines(String string) {
    try {/*from  w ww .j a v  a  2 s .co  m*/
        ArrayList<String> list = new ArrayList<String>();

        LineNumberReader reader = new LineNumberReader(new StringReader(string));
        String s;
        while ((s = reader.readLine()) != null) {
            list.add(s);
        }
        return list;
    } catch (IOException e) {
        // I don't think this can really happen with a StringReader.
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String getMacAddress() {
    String macAddress = null;/*from ww  w  .  j  a v a 2s  .  c  om*/
    LineNumberReader reader = null;
    try {
        Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
        InputStreamReader ir = new InputStreamReader(pp.getInputStream());
        reader = new LineNumberReader(ir);
        macAddress = reader.readLine().replace(":", "");
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (reader != null)
                reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return macAddress == null ? "" : macAddress;
}