Example usage for java.io FilterOutputStream write

List of usage examples for java.io FilterOutputStream write

Introduction

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

Prototype

@Override
public void write(byte b[], int off, int len) throws IOException 

Source Link

Document

Writes len bytes from the specified byte array starting at offset off to this output stream.

Usage

From source file:Main.java

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

    byte[] buffer = { 65, 66, 67, 68, 69 };
    int i = 0;/*from ww w .j  a  va2s .  co m*/
    OutputStream os = new FileOutputStream("C://test.txt");
    FilterOutputStream fos = new FilterOutputStream(os);

    // writes buffer to the output stream
    fos.write(buffer, 2, 3);

    // forces byte contents to written out to the stream
    fos.flush();

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

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

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

From source file:com.lizardtech.expresszip.model.Job.java

private void writeZipFile(File baseDir, File archive, List<String> files)
        throws FileNotFoundException, IOException {
    FilterOutputStream out = null;
    ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(archive));
    stream.setLevel(Deflater.DEFAULT_COMPRESSION);
    out = stream;/*  ww  w  . j av  a2 s. c o m*/

    byte data[] = new byte[18024];

    for (String f : files) {
        logger.info(String.format("Writing %s to ZIP archive %s", f, archive));
        ((ZipOutputStream) out).putNextEntry(new ZipEntry(f));

        BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(baseDir, f)));

        int len = 0;
        while ((len = in.read(data)) > 0) {
            out.write(data, 0, len);
        }

        out.flush();
        in.close();
    }

    out.close();
}