Java Reader Copy copyLarge(Reader input, Writer output)

Here you can find the source of copyLarge(Reader input, Writer output)

Description

copy Large

License

Apache License

Declaration

public static long copyLarge(Reader input, Writer output)
            throws IOException 

Method Source Code

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

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

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

public class Main {
    public static long copyLarge(InputStream input, OutputStream output)
            throws IOException {
        byte[] buffer = new byte[4096];
        long count = 0L;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);/*from  ww  w  .j a  v a  2s  . c  o  m*/
            count += n;
        }
        return count;
    }

    public static long copyLarge(Reader input, Writer output)
            throws IOException {
        char[] buffer = new char[4096];
        long count = 0L;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

    public static void write(byte[] data, OutputStream output)
            throws IOException {
        if (data != null)
            output.write(data);
    }

    public static void write(byte[] data, Writer output) throws IOException {
        if (data != null)
            output.write(new String(data));
    }

    public static void write(byte[] data, Writer output, String encoding)
            throws IOException {
        if (data != null)
            if (encoding == null)
                write(data, output);
            else
                output.write(new String(data, encoding));
    }

    public static void write(char[] data, Writer output) throws IOException {
        if (data != null)
            output.write(data);
    }

    public static void write(char[] data, OutputStream output)
            throws IOException {
        if (data != null)
            output.write(new String(data).getBytes());
    }

    public static void write(char[] data, OutputStream output,
            String encoding) throws IOException {
        if (data != null)
            if (encoding == null)
                write(data, output);
            else
                output.write(new String(data).getBytes(encoding));
    }

    public static void write(String data, Writer output) throws IOException {
        if (data != null)
            output.write(data);
    }

    public static void write(String data, OutputStream output)
            throws IOException {
        if (data != null)
            output.write(data.getBytes());
    }

    public static void write(String data, OutputStream output,
            String encoding) throws IOException {
        if (data != null)
            if (encoding == null)
                write(data, output);
            else
                output.write(data.getBytes(encoding));
    }

    public static void write(StringBuffer data, Writer output)
            throws IOException {
        if (data != null)
            output.write(data.toString());
    }

    public static void write(StringBuffer data, OutputStream output)
            throws IOException {
        if (data != null)
            output.write(data.toString().getBytes());
    }

    public static void write(StringBuffer data, OutputStream output,
            String encoding) throws IOException {
        if (data != null)
            if (encoding == null)
                write(data, output);
            else
                output.write(data.toString().getBytes(encoding));
    }

    public static String toString(InputStream input) throws IOException {
        StringWriter sw = new StringWriter();
        copy(input, sw);
        return sw.toString();
    }

    public static String toString(InputStream input, String encoding)
            throws IOException {
        StringWriter sw = new StringWriter();
        copy(input, sw, encoding);
        return sw.toString();
    }

    public static String toString(Reader input) throws IOException {
        StringWriter sw = new StringWriter();
        copy(input, sw);
        return sw.toString();
    }

    public static String toString(byte[] input) throws IOException {
        return new String(input);
    }

    public static String toString(byte[] input, String encoding)
            throws IOException {
        if (encoding == null) {
            return new String(input);
        }
        return new String(input, encoding);
    }

    public static int copy(InputStream input, OutputStream output)
            throws IOException {
        long count = copyLarge(input, output);
        if (count > 2147483647L) {
            return -1;
        }
        return (int) count;
    }

    public static void copy(InputStream input, Writer output)
            throws IOException {
        InputStreamReader in = new InputStreamReader(input);
        copy(in, output);
    }

    public static void copy(InputStream input, Writer output,
            String encoding) throws IOException {
        if (encoding == null) {
            copy(input, output);
        } else {
            InputStreamReader in = new InputStreamReader(input, encoding);
            copy(in, output);
        }
    }

    public static int copy(Reader input, Writer output) throws IOException {
        long count = copyLarge(input, output);
        if (count > 2147483647L) {
            return -1;
        }
        return (int) count;
    }

    public static void copy(Reader input, OutputStream output)
            throws IOException {
        OutputStreamWriter out = new OutputStreamWriter(output);
        copy(input, out);

        out.flush();
    }

    public static void copy(Reader input, OutputStream output,
            String encoding) throws IOException {
        if (encoding == null) {
            copy(input, output);
        } else {
            OutputStreamWriter out = new OutputStreamWriter(output,
                    encoding);
            copy(input, out);
            out.flush();
        }
    }
}

Related

  1. copyLarge(Reader input, Writer output)
  2. copyLarge(Reader input, Writer output)
  3. copyLarge(Reader input, Writer output)
  4. copyLarge(Reader input, Writer output)
  5. copyLarge(Reader input, Writer output)
  6. copyLarge(Reader input, Writer output)
  7. copyLarge(Reader input, Writer output)
  8. copyLarge(Reader input, Writer output, char[] buffer)
  9. copyLarge(Reader input, Writer output, char[] buffer)