Example usage for java.io BufferedInputStream BufferedInputStream

List of usage examples for java.io BufferedInputStream BufferedInputStream

Introduction

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

Prototype

public BufferedInputStream(InputStream in) 

Source Link

Document

Creates a BufferedInputStream and saves its argument, the input stream in, for later use.

Usage

From source file:PrimeReader.java

public static void main(String[] arguments) {
    try {//from  w  ww.j  a v a2  s . c  om
        FileInputStream file = new FileInputStream("400primes.dat");
        BufferedInputStream buff = new BufferedInputStream(file);
        DataInputStream data = new DataInputStream(buff);

        try {
            while (true) {
                int in = data.readInt();
                System.out.print(in + " ");
            }
        } catch (EOFException eof) {
            buff.close();
        }
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:Main.java

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

    boolean bool = false;

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // tests if the input stream supports mark() and reset()
    bool = fis.markSupported();//  w w w.j av  a 2 s . c o  m

    // prints
    System.out.print("Supports mark and reset methods: " + bool);

}

From source file:Main.java

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

    boolean bool = false;

    InputStream inStream = new FileInputStream("c:/test.txt");

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(inStream);

    // returns true if mark() and read() supports
    bool = bis.markSupported();//  w  w  w . j a  v  a  2 s  .c o m
    System.out.println("Support for mark() and reset() : " + bool);

}

From source file:BufferedCopy.java

public static void main(String[] args) throws Exception {
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    FileInputStream fis = new FileInputStream(args[0]);
    bis = new BufferedInputStream(fis);

    FileOutputStream fos = new FileOutputStream(args[1]);
    bos = new BufferedOutputStream(fos);

    int byte_;
    while ((byte_ = bis.read()) != -1)
        bos.write(byte_);
}

From source file:Main.java

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

    int i = 0;//  w ww  .  j a  v a2 s  .c om
    char c;

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // read till the end of the stream
    while ((i = fis.read()) != -1) {
        // converts integer to character
        c = (char) i;

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

}

From source file:Main.java

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

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // reads and prints filter input stream
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

    // mark invoked at this position
    fis.mark(0);/*from  w  w  w. ja v  a2 s . com*/
    System.out.println("mark() invoked");
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

    // reset() repositioned the stream to the mark
    fis.reset();
    System.out.println("reset() invoked");
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

}

From source file:Main.java

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

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // reads and prints BufferedReader
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

    // mark invoked at this position
    fis.mark(0);//from  w  ww .j a v a2 s .co m
    System.out.println("mark() invoked");
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

    // reset() repositioned the stream to the mark
    fis.reset();
    System.out.println("reset() invoked");
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

}

From source file:Main.java

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

    InputStream iStream = new FileInputStream("c:/test.txt");

    // input stream converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(iStream);

    // read and print characters one by one
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

    // mark is set on the input stream
    bis.mark(0);//  ww w.j av a2  s .  c  om
    System.out.println((char) bis.read());
    System.out.println("reset() invoked");

    // reset is called
    bis.reset();

    // read and print characters
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

}

From source file:Main.java

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

    byte[] buffer = new byte[6];

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // returns number of bytes read to buffer
    int i = fis.read(buffer);

    // prints/*from  www  . j av  a2 s  .  c om*/
    System.out.println("Number of bytes read: " + i);

    // for each byte in buffer
    for (byte b : buffer) {
        // converts byte to character
        char c = (char) b;

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

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InputStream is = new BufferedInputStream(new FileInputStream("s.gif"));
    Image image = ImageIO.read(is);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();//from   w  w w  .  j a v  a2  s . com
    frame.setVisible(true);
}