Java OutputStream Write writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer)

Here you can find the source of writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer)

Description

write Stream

License

LGPL

Declaration

public static int writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer)
            throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static int writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer)
            throws IOException {
        int totalWritten = 0;
        int read = 0;
        while ((read = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, read);
            totalWritten += read;//from ww  w .ja  v a 2  s.c om
        }

        return totalWritten;
    }

    public static int writeStream(OutputStream outputStream, InputStream inputStream) throws IOException {
        return writeStream(outputStream, inputStream, new byte[8192]);
    }

    public static int writeStream(OutputStream stream, String str) throws IOException {
        return writeStream(stream, str.getBytes("UTF-8"));
    }

    public static int writeStream(OutputStream stream, byte[] data) throws IOException {
        final InputStream fs = new ByteArrayInputStream(data);
        int totalWritten = writeStream(stream, fs);
        fs.close();

        return totalWritten;
    }
}

Related

  1. writeStream(InputStream _from, Writer _printTo)
  2. writeStream(InputStream in, File file)
  3. writeStream(InputStream inputStream, OutputStream out)
  4. writeStream(OutputStream out, byte[] data)
  5. writeStream(OutputStream output, String dataStr)
  6. writeStream(String content, String charset, OutputStream outputStream)
  7. writeStreamBuffered(final Reader in, final Writer out)
  8. writeStreamCharwise(final Reader in, final Writer out)
  9. writeStreamCharwiseLimited(final Reader in, final Writer out, final int len)