Here you can find the source of copyLarge(InputStream input, OutputStream output)
Parameter | Description |
---|---|
input | the InputStream to read from |
output | the OutputStream to write to |
Parameter | Description |
---|---|
IOException | if an I/O error occurs |
private static long copyLarge(InputStream input, OutputStream output) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 MadRobot.//from w ww. ja v a2 s .c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Elton Kent - initial API and implementation ******************************************************************************/ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static final int DEFAULT_BUFFER_SIZE = 1024 * 4; /** * Copy bytes from a large (over 2GB) InputStream to an OutputStream. * * This method buffers the input internally, so there is no need to use a BufferedInputStream. * * @param input * the InputStream to read from * @param output * the OutputStream to write to * @return the number of bytes copied * @throws IOException * if an I/O error occurs */ private static long copyLarge(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; long count = 0; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; } }