Here you can find the source of copyChannel(ReadableByteChannel in, long length, FileChannel out)
public static long copyChannel(ReadableByteChannel in, long length, FileChannel out) throws IOException
//package com.java2s; /*/* w ww .ja v a 2s.co m*/ * This file is part of the Jose Project * see http://jose-chess.sourceforge.net/ * (c) 2002-2006 Peter Sch?fer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ import java.io.*; import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; public class Main { public static long copyChannel(FileChannel in, long length, WritableByteChannel out) throws IOException { if (length < 0L || length >= Integer.MAX_VALUE) return in.transferTo(0L, length, out); long result = 0L; while (result < length) result += in.transferTo(result, length - result, out); return result; } public static long copyChannel(ReadableByteChannel in, long length, FileChannel out) throws IOException { if (length < 0L || length >= Integer.MAX_VALUE) return out.transferFrom(in, 0L, length); long result = 0L; while (result < length) result += out.transferFrom(in, result, length - result); return result; } }