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:Grep.java

public static void main(String args[]) throws Exception {
    String regex = "";
    InputStream in = System.in;

    regex = args[0];//from w w  w  .jav  a 2  s .  co m
    in = new BufferedInputStream(new FileInputStream(args[1]));
    Pattern p = null;

    p = Pattern.compile(regex);

    BufferedReader buff = new BufferedReader(new InputStreamReader(in));

    String a;
    for (a = buff.readLine(); a != null; a = buff.readLine()) {
        Matcher m = p.matcher(a);
        if (m.find()) {
            System.out.println(a);
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);/*from  w ww. ja  va 2  s  .c om*/
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close();
    System.setOut(console);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();//ww  w. j  av  a 2 s. co m

    // From file
    InputStream is = new BufferedInputStream(new FileInputStream(new File("midifile")));

    // From URL
    //    is = new BufferedInputStream(new URL("http://hostname/rmffile")
    //      .openStream());

    sequencer.setSequence(is);

    // Start playing
    sequencer.start();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();//  w  w  w.j a  v a  2  s.  c om

    // From file
    InputStream input = new BufferedInputStream(new FileInputStream(new File("midiaudiofile")));

    // From URL
    input = new BufferedInputStream(new URL("http://hostname/rmffile").openStream());

    sequencer.setSequence(input);

    // Start playing
    sequencer.start();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    //Read from an input stream
    InputStream is = new BufferedInputStream(new FileInputStream("source.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();// w w w .  j a  va2 s.  com
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    FileInputStream fis = new FileInputStream(zipname);
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;//from ww w.  j  a v  a2s.c  o m

    while ((entry = zis.getNextEntry()) != null) {
        System.out.println("Unzipping: " + entry.getName());

        int size;
        byte[] buffer = new byte[2048];

        FileOutputStream fos = new FileOutputStream(entry.getName());
        BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);

        while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    }
    zis.close();
    fis.close();
}

From source file:BufferedInputStreamDemo.java

public static void main(String args[]) throws IOException {
    String s = "This is a © copyright symbol " + "but this is &copy not.\n";
    byte buf[] = s.getBytes();
    ByteArrayInputStream in = new ByteArrayInputStream(buf);
    BufferedInputStream f = new BufferedInputStream(in);
    int c;//from   ww w  .j  a  v a  2 s  . c om
    boolean marked = false;

    while ((c = f.read()) != -1) {
        switch (c) {
        case '&':
            if (!marked) {
                f.mark(32);
                marked = true;
            } else {
                marked = false;
            }
            break;
        case ';':
            if (marked) {
                marked = false;
                System.out.print("(c)");
            } else
                System.out.print((char) c);
            break;
        case ' ':
            if (marked) {
                marked = false;
                f.reset();
                System.out.print("&");
            } else
                System.out.print((char) c);
            break;
        default:
            if (!marked)
                System.out.print((char) c);
            break;
        }
    }
}

From source file:MainClass.java

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

    Authenticator.setDefault(new DialogAuthenticator());

    URL u = new URL("secure url");
    InputStream in = u.openStream();
    in = new BufferedInputStream(in);
    Reader r = new InputStreamReader(in);
    int c;//from w  ww .  ja v  a 2 s .c o  m
    while ((c = r.read()) != -1) {
        System.out.print((char) c);
    }
}

From source file:TestEOF.java

public static void main(String[] args) throws IOException {
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("TestEOF.java")));
    while (in.available() != 0)
        System.out.print((char) in.readByte());
}

From source file:ReadBinaryFile.java

public static void main(String[] args) throws Exception {
    NumberFormat cf = NumberFormat.getCurrencyInstance();

    File file = new File("product.dat");
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));

    boolean eof = false;
    while (!eof) {
        Product movie = readMovie(in);//from   www. j  av  a2  s.c  o m
        if (movie == null)
            eof = true;
        else {
            String msg = Integer.toString(movie.year);
            msg += ": " + movie.title;
            msg += " (" + cf.format(movie.price) + ")";
            System.out.println(msg);
        }
    }
    in.close();
}