Here you can find the source of copy(ReadableByteChannel src, WritableByteChannel dest)
private static void copy(ReadableByteChannel src, WritableByteChannel dest) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Salesforce.com, inc.. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * /* www . jav a 2 s . co m*/ * Contributors: * Salesforce.com, inc. - initial API and implementation ******************************************************************************/ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; public class Main { /** * Helper method to copy from a readable channel to a writable channel, using an in-memory buffer. */ private static void copy(ReadableByteChannel src, WritableByteChannel dest) throws IOException { // use an in-memory byte buffer ByteBuffer buffer = ByteBuffer.allocate(8092); while (src.read(buffer) != -1) { buffer.flip(); while (buffer.hasRemaining()) { dest.write(buffer); } buffer.clear(); } } }