jodd-core/src/main/java/jodd/io/StreamUtil.java
public static int copy(final Reader input, final Writer output, final int count) throws IOException {
		if (count == ALL) {
			return copy(input, output);
		}

		int numToRead = count;
		char[] buffer = new char[numToRead];

		int totalRead = ZERO;
		int read;

		while (numToRead > ZERO) {
			read = input.read(buffer, ZERO, bufferSize(numToRead));
			if (read == NEGATIVE_ONE) {
				break;
			}
			output.write(buffer, ZERO, read);

			numToRead = numToRead - read;
			totalRead = totalRead + read;
		}

		output.flush();
		return totalRead;
	}
public static int copy(final Reader input, final Writer output, final int count) throws IOException {
		if (count == ALL) {
			return copy(input, output);
		}

		int numToRead = count;
		char[] buffer = new char[numToRead];

		int totalRead = ZERO;
		int read;

		while (numToRead > ZERO) {
			read = input.read(buffer, ZERO, bufferSize(numToRead));
			if (read == NEGATIVE_ONE) {
				break;
			}
			output.write(buffer, ZERO, read);

			numToRead = numToRead - read;
			totalRead = totalRead + read;
		}

		output.flush();
		return totalRead;
	}
public static int copy ( final Reader input , final Writer output , final int count ) throws IOException { if ( count == ALL ) { return copy ( input , output ) ; } int numToRead = count ; char [ ] buffer = new char [ numToRead ] ; int totalRead = ZERO ; int read ; while ( numToRead > ZERO ) { read = input . read ( buffer , ZERO , bufferSize ( numToRead ) ) ; if ( read == NEGATIVE_ONE ) { break ; } output . write ( buffer , ZERO , read ) ; numToRead = numToRead - read ; totalRead = totalRead + read ; } output . flush ( ) ; return totalRead ; }
Copies specified number of characters from {@link Reader} to {@link Writer} using buffer.
{@link Reader} and {@link Writer} don't have to be wrapped to buffered, since copying is already optimized.

@param input  {@link Reader} to read.
@param output {@link Writer} to write to.
@param count  The number of characters to read.
@return The total number of characters read.
@throws IOException if there is an error reading or writing.
Copies specified number of characters from { @link Reader } to { @link Writer } using buffer . { @link Reader } and { @link Writer } don t have to be wrapped to buffered since copying is already optimized .