Example usage for java.io BufferedOutputStream flush

List of usage examples for java.io BufferedOutputStream flush

Introduction

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

Prototype

@Override
public synchronized void flush() throws IOException 

Source Link

Document

Flushes this buffered output stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream(new File("C:/Demo"));
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    bos.write("this is a test".getBytes());
    bos.flush();
    bos.close();/*from  w  w  w  .  j  a  v a2  s  . com*/
}

From source file:Main.java

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    BufferedOutputStream bos = new BufferedOutputStream(baos);

    int b = 87;//w w  w .  ja va2  s .c  om

    bos.write(b);

    bos.flush();

    byte[] bytes = baos.toByteArray();

    System.out.println(bytes[0]);

}

From source file:Main.java

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(baos);

    byte[] bytes = { 1, 2, 3, 4, 5 };

    bos.write(bytes, 0, 5);/*  ww  w.  java 2 s  . co m*/

    bos.flush();

    for (byte b : baos.toByteArray()) {
        System.out.print(b);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/Demo.txt");
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    byte b = 66;/*  w  w  w  . j  a  v a2  s.  co  m*/
    // write a character represented by ascii 66 i.e. 'B'
    bos.write(b);
    bos.flush();
    bos.close();
}

From source file:org.deeplearning4j.plot.dropwizard.RenderApplication.java

public static void main(String[] args) throws Exception {
    ClassPathResource resource = new ClassPathResource("/render/dropwizard.yml");
    InputStream is = resource.getInputStream();
    File tmpConfig = new File("dropwizard-render.yml");
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpConfig));
    IOUtils.copy(is, bos);//from   w w w .ja v a  2s .c  om
    bos.flush();
    bos.close();
    is.close();
    tmpConfig.deleteOnExit();
    new RenderApplication().run("server", tmpConfig.getAbsolutePath());
}

From source file:Main.java

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

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

    BufferedInputStream bis = new BufferedInputStream(is);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    BufferedOutputStream bos = new BufferedOutputStream(baos);

    int value;/*from   w  w  w  . ja  va2  s  . co  m*/

    while ((value = bis.read()) != -1) {
        bos.write(value);
    }

    bos.flush();

    for (byte b : baos.toByteArray()) {

        char c = (char) b;
        System.out.println(c);
    }

}

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 a  2 s .c  om

    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: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);// w ww.j  a v a  2s  . c o m
        while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
        bis.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;/*  w w w .java 2 s  .  c o  m*/

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

public static void main(String args[]) {
    if (args.length != 1) {
        System.err.println("Syntax: <java Blobs [driver] [url] " + "[uid] [pass] [file]");
        return;//from   w  w w .  j  a  v  a 2  s .com
    }
    try {
        Class.forName(args[0]).newInstance();
        Connection con = DriverManager.getConnection(args[1], args[2], args[3]);
        File f = new File(args[4]);
        PreparedStatement stmt;

        if (!f.exists()) {
            // if the file does not exist
            // retrieve it from the database and write it to the named file
            ResultSet rs;

            stmt = con.prepareStatement("SELECT blobData " + "FROM BlobTest " + "WHERE fileName = ?");

            stmt.setString(1, args[0]);
            rs = stmt.executeQuery();
            if (!rs.next()) {
                System.out.println("No such file stored.");
            } else {
                Blob b = rs.getBlob(1);
                BufferedOutputStream os;

                os = new BufferedOutputStream(new FileOutputStream(f));
                os.write(b.getBytes(0, (int) b.length()), 0, (int) b.length());
                os.flush();
                os.close();
            }
        } else {
            // otherwise read it and save it to the database
            FileInputStream fis = new FileInputStream(f);
            byte[] tmp = new byte[1024];
            byte[] data = null;
            int sz, len = 0;

            while ((sz = fis.read(tmp)) != -1) {
                if (data == null) {
                    len = sz;
                    data = tmp;
                } else {
                    byte[] narr;
                    int nlen;

                    nlen = len + sz;
                    narr = new byte[nlen];
                    System.arraycopy(data, 0, narr, 0, len);
                    System.arraycopy(tmp, 0, narr, len, sz);
                    data = narr;
                    len = nlen;
                }
            }
            if (len != data.length) {
                byte[] narr = new byte[len];

                System.arraycopy(data, 0, narr, 0, len);
                data = narr;
            }
            stmt = con.prepareStatement("INSERT INTO BlobTest(fileName, " + "blobData) VALUES(?, ?)");
            stmt.setString(1, args[0]);
            stmt.setObject(2, data);
            stmt.executeUpdate();
            f.delete();
        }
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}