Example usage for java.io LineNumberInputStream LineNumberInputStream

List of usage examples for java.io LineNumberInputStream LineNumberInputStream

Introduction

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

Prototype

public LineNumberInputStream(InputStream in) 

Source Link

Document

Constructs a newline number input stream that reads its input from the specified input stream.

Usage

From source file:Main.java

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

    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    lnis.setLineNumber(100);//from  w w  w . j  a  va2  s.c om

    int i = lnis.getLineNumber();

    System.out.print("Line number: " + i);

}

From source file:Main.java

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

    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);
    int i;/*from   w ww .  j  ava2s .  c  o m*/
    while ((i = lnis.read()) != -1) {

        char c = (char) i;

        System.out.println("Character read: " + c);

        int j = lnis.available();

        System.out.println("Available bytes: " + j);
    }

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    lnis.mark(0);/*from  w w  w. j  av a 2  s  .c o  m*/
    System.out.println("mark() invoked");
    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    if (lnis.markSupported()) {
        lnis.reset();
        System.out.println("reset() invoked");
        System.out.println((char) lnis.read());
        System.out.println((char) lnis.read());
    }

}

From source file:Main.java

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

    int i;/*www. j  av  a  2  s  .c o m*/

    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    while ((i = lnis.read()) != -1) {
        char c = (char) i;

        System.out.print(c);
    }
}

From source file:Main.java

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

    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    lnis.mark(0);/* w  ww .j a v  a 2  s  .  co  m*/
    System.out.println("mark() invoked");
    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    if (lnis.markSupported()) {
        lnis.reset();
        System.out.println("reset() invoked");
        System.out.println((char) lnis.read());
        System.out.println((char) lnis.read());
    }

}

From source file:Main.java

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

    int i;// w  w w . j a va  2  s. c  o m
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    while ((i = lnis.read()) != -1) {
        char c = (char) i;

        System.out.println(c);

        lnis.skip(1);
    }

}

From source file:Main.java

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

    int i;//from   w w w . j  av  a  2  s. c  o m
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    while ((i = lnis.read()) != -1) {
        char c = (char) i;

        if (i != 10) {
            System.out.println("Character read: " + c);

            int j = lnis.getLineNumber();
            System.out.println(" at line: " + j);
        }
    }

}

From source file:Main.java

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

    byte[] buf = new byte[5];

    char c;//www .  j av a2 s  .  c o  m

    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    int i = lnis.read(buf, 2, 3);
    System.out.println("The number of char read: " + i);

    for (byte b : buf) {
        if (b == 0)
            c = '-';
        else
            c = (char) b;

        System.out.print(c);
    }

}