import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Calendar; import java.util.Date; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; public class MyFilesystemParser { File logFile; private String curLine; private String ignoreDir; private long counter; public long cmpcounter; public long dumpcounter; public MyFilesystemParser(String logfile) { logFile = new File(logfile+".gz"); ignoreDir = System.getProperty("user.dir"); while (ignoreDir.charAt(ignoreDir.length()-1)=='\\') ignoreDir = ignoreDir.substring(0, ignoreDir.length()-1); } public boolean driveIsWritable(char drive) { File flTest = new File (drive+":\\"); return flTest.canWrite(); } public boolean driveExists(char drive) { File flTest = new File(drive+":\\"); return flTest.exists(); } public boolean driveIsReadable(char drive) { File flTest = new File(drive+":\\"); return flTest.canRead(); } /* public File[] listRoots() { File[] result = new File[1]; result[0] = new File("E:\\"); return result; } */ public File[] listRoots() { int count = 0; for (char d='A';d<='Z';d++) { if (driveExists(d)) count++; } File[] result = new File[count]; count = 0; for (char d='A';d<='Z';d++) { if (driveExists(d)) result[count++] = new File(d+":\\"); } return result; } /** Returns all files of a specified directory ATTENTION! ignoreDir has to contain a directory which should be ignored (temp, etc.). The String must have no trailing backslash or slash. Also keep in mind that we work with equalsIgnoreCase - so this won't work correctly on UNIXish machines @param dir Directory to get contents of @param noIgnoreDir If false, the startup-directory is ignored (because there are temporary files, data files, etc.) @return File[] with File-Objects of all files in that directory */ public File[] listFiles(File dir, boolean noIgnoreDir) { String[] files = dir.list(); File[] result; if ( files != null && ( !dir.getAbsolutePath().equalsIgnoreCase(ignoreDir) || noIgnoreDir )) { result = new File[files.length]; for (int i=0; i 0) hi--; while (lge(files[lo].getName(), p) < 0) lo++; if (lo < hi) { swap(files, lo++, hi--); } else { return hi; } } return hi; } /** QuickSort implementation */ public void sortQuick(File[] files, int lo, int hi) { if (lo0 && files[0].isDirectory()) x=1; else x=0; File tmp; for (int i=1;ix;j--) { files[j] = files[j-1]; } files[x] = tmp; x++; } } } /** Returns the sorted files-array */ public File[] sortDir(File[] files) { if (files.length>=2) { sortQuick(files, 0, files.length-1); // sortDirsFirst(files); } return files; } /** Writes all file-entries incl. size and time of dir and sub-dirs to fw */ public void dumpFiles(BufferedOutputStream fw, File dir) throws IOException { File[] entries = sortDir(listFiles(dir, false)); for (int i=0; i0 && fn.substring(fn.length()-mask.length()).equals(mask)) { tmp = new String[result.length+1]; for (int j=0;j