Java Reader Copy copyLarge(Reader input, Writer output)

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

Description

copy Large

License

Mozilla Public License

Declaration

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

Method Source Code


//package com.java2s;
/*/*  w  w w. ja  va 2 s . c  o  m*/
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF
 *
 * ANY KIND, either express or implied. See the License for the specific language governing rights and
 *
 * limitations under the License.
 *
 * The Original Code is the IZAYOI web framework.
 *
 * The Initial Developer of the Original Code is
 *
 *   Mo Chen <withinsea@gmail.com>
 *
 * Portions created by the Initial Developer are Copyright (C) 2009-2010
 * the Initial Developer. All Rights Reserved.
 */

import java.io.*;

public class Main {
    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;

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

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

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

    public static void write(String data, File file, String encoding) throws IOException {
        File parentFile = file.getParentFile();
        if ((parentFile.exists() && parentFile.isDirectory()) || parentFile.mkdirs()) {
            FileOutputStream fos = new FileOutputStream(file);
            write(data, fos, encoding);
            fos.close();
        }
    }
}

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)
  9. copyLarge(Reader input, Writer output)