Java InputStream Copy copyStream(Reader in, Writer out)

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

Description

copy Stream

License

Apache License

Declaration

public static void copyStream(Reader in, Writer out) throws IOException 

Method Source Code

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

import java.io.*;

public class Main {
    public static void copyStream(Reader in, Writer out) throws IOException {
        char[] buffer = new char[2048];
        int nread;
        int col = 0;
        try {//from  ww w  .  j a  v  a 2 s .c om
            nread = in.read(buffer);
            while (nread > 0) {
                out.write(buffer, 0, nread);
                nread = in.read(buffer);
                System.out.print(".");
                if (col++ > 60) {
                    System.out.println();
                    col = 0;
                }
            }
        } finally {
            System.out.println();
            in.close();
            out.close();
        }
    }

    public static void copyStream(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[2048];
        int nread;
        int col = 0;
        try {
            nread = in.read(buffer);
            while (nread > 0) {
                out.write(buffer, 0, nread);
                nread = in.read(buffer);
                System.out.print(".");
                if (col++ > 60) {
                    System.out.println();
                    col = 0;
                }
            }
        } finally {
            System.out.println();
            in.close();
            out.close();
        }
    }
}

Related

  1. copyLarge(InputStream input, OutputStream output, long limit)
  2. copyStream(final BufferedReader in, final PrintWriter out, final String[] mapFrom, String[] mapTo)
  3. copyStream(InputStream is)
  4. copyStream(InputStream is)
  5. copyStream(InputStream iss)
  6. copyStream(Reader in, Writer out)
  7. copyStream(Reader reader, Writer writer)
  8. copyStream(ZipInputStream in, ZipEntry entry)
  9. copyStreamBytes(InputStream is)