package org.to2mbn.jmccc.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public final class FileUtils {

	public static void mkdirs(File dir) throws IOException {
		if (!dir.mkdirs()) {
			throw new IOException("Cannot mkdirs: " + dir);
		}
	}
	
	public static void testRead(File file) throws IOException {
		if (!file.canRead()) {
			throw new IOException("Cannot read from: " + file);
		}
	}

	public static void testWrite(File file) throws IOException {
		if (!file.canWrite()) {
			throw new IOException("Cannot write to: " + file);
		}
	}

	public static void prepareWrite(File file) throws IOException {
		File parent = file.getParentFile();
		if (parent != null && !parent.exists()) {
			mkdirs(parent);
		}
	}
	
	public static void copyFile(File src, File target) throws IOException {
		prepareWrite(target);
		try (FileInputStream in = new FileInputStream(src); FileOutputStream out = new FileOutputStream(target)) {
			FileChannel chin = in.getChannel();
			FileChannel chout = out.getChannel();
			chin.transferTo(0, chin.size(), chout);
		}
	}

	private FileUtils() {
	}
}

package org.to2mbn.jmccc.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public final class FileUtils {

	public static void mkdirs(File dir) throws IOException {
		if (!dir.mkdirs()) {
			throw new IOException("Cannot mkdirs: " + dir);
		}
	}
	
	public static void prepareWrite(File file) throws IOException {
		File parent = file.getParentFile();
		if (parent != null && !parent.exists()) {
			mkdirs(parent);
		}
	}

	public static void copyFile(File src, File target) throws IOException {
		prepareWrite(target);
		try (FileInputStream in = new FileInputStream(src); FileOutputStream out = new FileOutputStream(target)) {
			FileChannel chin = in.getChannel();
			FileChannel chout = out.getChannel();
			chin.transferTo(0, chin.size(), chout);
		}
	}

	private FileUtils() {
	}
}

remove testWrite() & testRead()