View Javadoc

1   package com.insanityengine.ghia.util;
2   
3   import java.io.File;
4   import java.util.Vector;
5   import java.util.Stack;
6   
7   /***
8    *
9    * <P>
10   * </P>
11   *
12   * @author BrianHammond
13   *
14   * $Header: /usr/local/cvsroot/ghia/src/java/com/insanityengine/ghia/util/FileTree.java,v 1.7 2005/03/19 17:50:02 brian Exp $
15   *
16   */
17  
18  public class FileTree {
19  	
20  	//
21  
22  	/***
23  	 *
24  	 */
25  	public FileTree() {
26  		reset();
27  	}
28  
29  	/***
30  	 *
31  	 */
32  	public FileTree( String start ) throws java.io.IOException {
33  		init( start );
34  	}
35  	
36  	public FileTree( File f ) throws java.io.IOException {
37  		init( f );
38  	}
39  	
40  	/***
41  	 *
42  	 */
43  	public FileTree( String start, FileTree parent ) throws java.io.IOException {
44  		init( start, parent );
45  	}
46  
47  	/***
48  	 *
49  	 */
50  	public FileTree( File f, FileTree parent ) throws java.io.IOException {
51  		init( f, parent );
52  	}
53  
54  	/***
55  	 *
56  	 */
57  	public void reset() {
58  		file = null;
59  		parent = null;
60  		kidz = null;
61  		isDir = false;
62  		length = kid_len = desc_len = kid_count = desc_count = 0;
63  	}
64  
65  	/***
66  	 *
67  	 */
68  	public void init( String start ) throws java.io.IOException {
69  		init( new File( start ), null );
70  	}
71  	
72  	/***
73  	 *
74  	 */
75  	public void init( String start, FileTree p ) throws java.io.IOException {
76  		init( new File( start ), p );
77  	}
78  
79  	/***
80  	 *
81  	 */
82  	public void init( File f ) throws java.io.IOException {
83  		init( f, null );
84  	}
85  	
86  	/***
87  	 *
88  	 */
89  	public void init( File f, FileTree p ) throws java.io.IOException {
90  		reset();
91  
92  		file = f;
93  		parent = p;
94  
95  		// collect some file info
96  		length = file.length();
97  
98  		if ( !file.isDirectory() ) {
99  			return;	
100 		}
101 
102 		isDir = true;
103 
104 		File[] files = file.listFiles();
105 		if ( null == files ) { 
106 			return;
107 		}
108 
109         //length = kid_count = desc_count = 0;
110 		
111 		kid_count = files.length;
112 		kidz = new FileTree[ ( int ) kid_count ];
113 		for ( int i = 0 ; i < kid_count ; i++ ) {
114 			FileTree kid = kidz[ i ] = new FileTree( files[ i ], this );
115 
116 			desc_count += 1 + kid.desc_count;
117 			desc_len   += kid.desc_len + kid.length;
118 			kid_len    += kid.kid_len  + kid.length;
119 		}
120 	}
121 
122 	/***
123 	 *
124 	 * Get the number of descendants
125 	 *
126 	 * @return the number of descendants
127 	 *
128 	 */
129 	public long getDescendantCount() { return desc_count; }
130 
131 	// private
132 
133 	private File file = null;
134 	private FileTree parent = null;
135 	private FileTree kidz[] = null;
136 
137 	private boolean isDir = false;
138 	private long length, kid_len, desc_len, kid_count, desc_count;
139 
140 	
141 };
142 
143 /***
144  *
145  * $Log: FileTree.java,v $
146  * Revision 1.7  2005/03/19 17:50:02  brian
147  * repackaging
148  *
149  * Revision 1.6  2004/09/01 01:10:42  brian
150  * fix class level javadoc placement
151  *
152  * Revision 1.5  2004/09/01 00:11:06  brian
153  * author, log and header stuff
154  *
155  *
156  */