Author: brandonwilliams Date: Mon Sep 20 18:47:08 2010 New Revision: 999050
URL: http://svn.apache.org/viewvc?rev=999050&view=rev Log: Add removed methods in FileUtils back. Patch by Nate McCall, reviewed by brandonwilliams for CASSANDRA-1522 Modified: cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java Modified: cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java?rev=999050&r1=999049&r2=999050&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java Mon Sep 20 18:47:08 2010 @@ -83,6 +83,19 @@ public class FileUtils } } + public static void createFile(String directory) throws IOException + { + File file = new File(directory); + if ( !file.exists() ) + file.createNewFile(); + } + + public static boolean isExists(String filename) throws IOException + { + File file = new File(filename); + return file.exists(); + } + public static boolean delete(String file) { File f = new File(file); @@ -106,6 +119,14 @@ public class FileUtils return bVal; } + public static void delete(File[] files) throws IOException + { + for ( File file : files ) + { + file.delete(); + } + } + public static String stringifyFileSize(double value) { double d; @@ -139,6 +160,29 @@ public class FileUtils return val + " bytes"; } } + + /** + * calculate the total space used by a file or directory + * + * @param path the path + * @return total space used. + */ + public static long getUsedDiskSpaceForPath(String path) + { + File file = new File(path); + + if (file.isFile()) + { + return file.length(); + } + + long diskSpace = 0; + for (File childFile: file.listFiles()) + { + diskSpace += getUsedDiskSpaceForPath(childFile.getPath()); + } + return diskSpace; + } /** * Deletes all files and subdirectories under "dir".
