Java Reader Copy copyLarge(Reader input, Writer output, long limit)

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

Description

copy Large

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
/*//from   ww w. j  a v a2s. c om
 * 
 * 
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.io.IOException;

import java.io.Reader;

import java.io.Writer;

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

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

Related

  1. copyLarge(Reader input, Writer output)
  2. copyLarge(Reader input, Writer output, char[] buffer)
  3. copyLarge(Reader input, Writer output, char[] buffer)
  4. copyLarge(Reader input, Writer output, char[] buffer)
  5. copyLarge(Reader input, Writer output, final long inputOffset, final long length, char[] buffer)