Java Utililty Methods FileChannel Copy

List of utility methods to do FileChannel Copy

Description

The list of methods to do FileChannel Copy are organized into topic(s).

Method

intcopy(FileInputStream in, FileOutputStream out)
Copies bytes from a FileInputStream to a FileOutputStream.
final long count = copyLarge(in, out);
return count > Integer.MAX_VALUE ? -1 : (int) count;
voidcopy(FileInputStream inputStream, FileOutputStream outputStream)
copy
FileChannel srcChannel = null;
FileChannel desChannel = null;
try {
    srcChannel = inputStream.getChannel();
    desChannel = outputStream.getChannel();
    srcChannel.transferTo(0, srcChannel.size(), desChannel);
    srcChannel.close();
    desChannel.close();
...
voidcopy(FileInputStream iStream, FileOutputStream oStream)
Special optimized version of copying a FileInputStream to a FileOutputStream .
try {
    FileChannel inChannel = iStream.getChannel();
    FileChannel outChannel = oStream.getChannel();
    long fileSize = inChannel.size();
    long offs = 0, doneCnt = 0, copyCnt = Math.min(65536, fileSize);
    do {
        doneCnt = inChannel.transferTo(offs, copyCnt, outChannel);
        offs += doneCnt;
...
voidcopy(final File aCopyFrom, final File aCopyTo)
This is a copy of the Utils package copy.
if (!aCopyTo.getParentFile().isDirectory() && !aCopyTo.getParentFile().mkdirs()) {
    throw new IOException("Could not create copy to directory: " + aCopyTo.getAbsolutePath());
FileChannel lSrcChannel = new FileInputStream(aCopyFrom).getChannel();
FileChannel lDstChannel = new FileOutputStream(aCopyTo).getChannel();
Logger.getAnonymousLogger().fine("\tCopying from \"" + aCopyFrom.getCanonicalPath() + "\" to \""
        + aCopyTo.getCanonicalPath() + "\"");
lDstChannel.transferFrom(lSrcChannel, 0, lSrcChannel.size());
...
booleancopy(final File fromFile, final File toFile)
Copy a File.
try {
    copyThrowsOnException(fromFile, toFile);
    return true;
} catch (IOException e) {
    e.printStackTrace();
    return false;
voidcopy(final File source, final File dest)
copy
final FileChannel inChannel = new FileInputStream(source).getChannel();
final FileChannel outChannel = new FileOutputStream(dest).getChannel();
try {
    final int maxCount = (64 * 1024 * 1024) - (32 * 1024);
    final long size = inChannel.size();
    long position = 0;
    while (position < size)
        position += inChannel.transferTo(position, maxCount, outChannel);
...
voidcopy(final File src, File dst, final boolean overwrite)
Copy source file to destination.
if (!src.isFile() || !src.exists()) {
    throw new IllegalArgumentException("Source file '" + src.getAbsolutePath() + "' not found!"); 
if (dst.exists()) {
    if (dst.isDirectory()) {
        dst = new File(dst, src.getName());
    } else if (dst.isFile()) {
        if (!overwrite) {
...
voidcopy(final String aSrcPath, final String aDestPath)
copy
copy(new File(aSrcPath), new File(aDestPath));
voidcopy(final String aSrcPath, final String aDestPath)
copy
copy(new File(aSrcPath), new File(aDestPath));
voidcopy(String fromPath, String toPath)
copy
File sourceFile = new File(fromPath);
FileInputStream input = null;
FileOutputStream output = null;
FileChannel fcin = null;
FileChannel fcout = null;
input = new FileInputStream(sourceFile);
output = new FileOutputStream(toPath);
fcin = input.getChannel();
...