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

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeChars("java2s.com");
    out.close();/*  w w  w . ja  v  a 2  s .co m*/

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeBytes("java2s.com");
    out.close();//from w w w.  j a  v  a  2s  .  c  o m

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeLong(1111111111111L);/*from  ww  w .  j  ava 2 s.  c  o  m*/
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "d.zip";
    CheckedInputStream checksum = new CheckedInputStream(new FileInputStream(zipname), new Adler32());
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
    ZipEntry entry;/*from   w  w w.  j a v a  2 s  .  c  om*/

    while ((entry = zis.getNextEntry()) != null) {
        System.out.println("Unzipping: " + entry.getName());
        int size;
        byte[] buffer = new byte[2048];

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entry.getName()),
                buffer.length);
        while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    }

    zis.close();
    System.out.println("Checksum = " + checksum.getChecksum().getValue());
}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.write("java2s.com".getBytes());
    out.close();//from   w  ww.  java  2 s  .c om

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

  public static void main(String[] args) throws IOException {
  ServerSocket servsock = new ServerSocket(123456);
  File myFile = new File("s.pdf");
  while (true) {//  ww w.  j  av  a  2s .c  o  m
    Socket sock = servsock.accept();
    byte[] mybytearray = new byte[(int) myFile.length()];
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile));
    bis.read(mybytearray, 0, mybytearray.length);
    OutputStream os = sock.getOutputStream();
    os.write(mybytearray, 0, mybytearray.length);
    os.flush();
    sock.close();
  }
}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.write("java2s.com".getBytes(), 1, 2);
    out.close();/* ww w . java  2s  .c o  m*/

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt")));
    out2.writeDouble(3.14159);//from w ww  . java  2  s  . co  m
    out2.writeUTF("Square root of 2");
    out2.close();

    DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt")));

    System.out.println(in5.readDouble());
    System.out.println(in5.readUTF());
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Date today = new Date();
    long millisecondsPerDay = 24 * 60 * 60 * 1000;

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    uc.setIfModifiedSince((new Date(today.getTime() - millisecondsPerDay)).getTime());
    InputStream in = new BufferedInputStream(uc.getInputStream());
    Reader r = new InputStreamReader(in);
    int c;// w  w  w .j ava 2 s .co m
    while ((c = r.read()) != -1) {
        System.out.print((char) c);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    ZipFile zipFile = new ZipFile(zipname);
    Enumeration enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
        System.out.println("Unzipping: " + zipEntry.getName());
        BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
        int size;
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(zipEntry.getName()),
                buffer.length);/*from   ww w .  j a v a2s  . c  o m*/
        while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
        bis.close();
    }
}