diff --git a/MyFilesystemParser.java b/MyFilesystemParser.java new file mode 100644 index 0000000..9cbbcc9 --- /dev/null +++ b/MyFilesystemParser.java @@ -0,0 +1,333 @@ +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.IOException; + +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 long counter; + + public MyFilesystemParser(String logfile) { + logFile = new File(logfile+".gz"); + } + + 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 */ + public File[] listFiles(File dir) { + String[] files = dir.list(); + File[] result; + if (files != null) { + 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)); + for (int i=0; i0 && fn.substring(fn.length()-mask.length()).equals(mask)) { + tmp = new String[result.length+1]; + for (int j=0;j