Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Stuck on a caching issue.

Reply
Thread Tools

Stuck on a caching issue.

 
 
Paul Lutus
Guest
Posts: n/a
 
      10-21-2004
Inertia_sublimation wrote:

> Paul Lutus <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>> The required addition to my program would be a Vector (or ArrayList), to
>> which you would add entries for each visited directory, recursively. You
>> could create a utility class that contained a total number plus a vector
>> containing all the visited directories for that level. Each visited
>> directory would get an instance of this utility class added to the vector
>> for the higher level.


> By "total number" do you mean size?


I'll say it differently. I mean a number that represents the sum of the
lengths of all the files you encountered during your scan. The total number
for the root directory should be the grand total of the lengths of all the
files on the entire scanned directory tree -- e.g. the sum of all the
individual sums from the subdirectories.

Just as my original program does it, but with a browsable tree structure at
the end of the process. Like this:

************************************************** ******************

// DirSum.java

import java.io.*;
import java.util.*;

public class DirSum {

private boolean isSymLink(File f) {
try {
return !f.getCanonicalPath().equals(f.getAbsolutePath());
}
catch (java.io.IOException e) {
return false;
}
}

public DirData scanSimple(File path,boolean showResult) {
DirData data = new DirData();
File[] list = path.listFiles();
if(list != null) {
Arrays.sort(list);
for(int i = 0; i < list.length;i++) {
File f = list[i];
// don't follow symlinks
if(f.isDirectory()) {
if(isSymLink(f)) {
data.addSymlink();
}
else {
data.addDirectory(scanSimple(f,showResult));
}
}
else {
data.addFile(f);
}
}
}
if(showResult) {
System.out.println(path + ": " + data);
}
return data;
}

public static void main(String args[]) {
if(args.length == 0) {
System.out.println("usage: directory to be scanned.");
}
else {
DirSum s = new DirSum();
DirData d = s.scanSimple(new File(args[0]),false);
System.out.println("Total for " + args[0] + ": " + d);
}
}
}

class DirData {
private long symlinks = 0;
private long files = 0;
private long length = 0;
private long directories = 1;
private ArrayList subDirs = new ArrayList();

public final ArrayList getSubs() {
return subDirs;
}

public void addFile(File f) {
files++;
length += f.length();
}

public void addSymlink() {
symlinks++;
}

public long getFiles() {
return files;
}

public long getLength() {
return length;
}

public long getDirs() {
return directories;
}

public long getSymlinks() {
return symlinks;
}

public void addDirectory(DirData d) {
subDirs.add(d);
directories += d.getDirs();
files += d.getFiles();
length += d.getLength();
}

public String toString() {
return files + " files, " + directories + " dirs, " + symlinks
+ " symlinks, " + length + " bytes.";
}
}

************************************************** ******************

In this line:

DirData d = s.scanSimple(new File(args[0]),false);

What is returned is an instance of the DirData class that contains within it
a nested ArrayList of all the visited directories, arranged as a tree
structure. You can traverse the tree to get the information you need.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable page caching without disabling caching of jpegs andstylesheets etc JimLad ASP .Net 3 01-21-2010 10:13 AM
Dlink di-784 freezing / lights stuck on markm75c@msn.com Wireless Networking 6 07-05-2006 03:36 PM
Wireless Network Connection Stuck on "Acquiring Network Address" =?Utf-8?B?bmlja3Nwb29u?= Wireless Networking 4 10-20-2005 07:31 AM
Fragment Caching inside page caching? Troy Simpson ASP .Net 0 01-19-2004 11:57 AM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM



Advertisments