Java OutputStream Write writeStreamBuffered(final Reader in, final Writer out)

Here you can find the source of writeStreamBuffered(final Reader in, final Writer out)

Description

write Stream Buffered

License

Open Source License

Declaration

public static int writeStreamBuffered(final Reader in, final Writer out) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.io.Reader;
import java.io.Writer;

public class Main {
    public static final int DEFAULT_BUFFER_SIZE = 8192;

    public static int writeStreamBuffered(final Reader in, final Writer out) throws IOException {
        return writeStreamBuffered(in, out, DEFAULT_BUFFER_SIZE);
    }/*from  w  ww  .  j  a  v a2 s.c  o m*/

    public static int writeStreamBuffered(final Reader in, final Writer out, final int bufferSize)
            throws IOException {
        final char[] cbuf = new char[bufferSize];
        return writeStreamBuffered(in, out, cbuf);
    }

    public static int writeStreamBuffered(final Reader in, final Writer out, final char[] cbuf) throws IOException {
        int read;
        int count = 0;

        while (true) {
            read = in.read(cbuf);
            if (read == -1) {
                return count;
            }

            out.write(cbuf, 0, read);
            count += read;
        }
    }
}

Related

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