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() {
	}
}

@@ -355,307 +355,8 @@
 %7D%0A%09%0A
-%09public static void testRead(File file) throws IOException %7B%0A%09%09if (!file.canRead()) %7B%0A%09%09%09throw new IOException(%22Cannot read from: %22 + file);%0A%09%09%7D%0A%09%7D%0A%0A%09public static void testWrite(File file) throws IOException %7B%0A%09%09if (!file.canWrite()) %7B%0A%09%09%09throw new IOException(%22Cannot write to: %22 + file);%0A%09%09%7D%0A%09%7D%0A%0A
 %09pub
@@ -516,33 +516,32 @@
 parent);%0A%09%09%7D%0A%09%7D%0A
-%09
 %0A%09public static 

remove testWrite() & testRead()