/**
* Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
* EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
* http://www.ewcms.com
*/
package com.ewcms.plugin.crawler.generate.util;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
/**
* @author Yasser Ganjisaffar <lastname at gmail dot com>
*/
public class IO {
public static boolean deleteFolder(File folder) {
return deleteFolderContents(folder) && folder.delete();
}
public static boolean deleteFolderContents(File folder) {
System.out.println("Deleting content of: " + folder.getAbsolutePath());
File[] files = folder.listFiles();
for (File file : files) {
if (file.isFile()) {
if (!file.delete()) {
return false;
}
} else {
if (!deleteFolder(file)) {
return false;
}
}
}
return true;
}
public static void writeBytesToFile(byte[] bytes, String destination) {
FileChannel fc = null;
try {
fc = new FileOutputStream(destination).getChannel();
fc.write(ByteBuffer.wrap(bytes));
fc.close();
} catch (Exception e) {
} finally {
try {
if (fc != null){
fc.close();
fc = null;
}
} catch (IOException e){}
}
}
}