1 import jcifs.smb.SmbFile; 2 import java.util.LinkedList ; 3 import java.util.ListIterator ; 4 import java.net.MalformedURLException ; 5 import java.io.IOException ; 6 7 public class CrawlTest extends Thread { 8 9 SmbFile f; 10 int maxDepth; 11 12 CrawlTest( SmbFile f, int maxDepth ) { 13 this.f = f; 14 this.maxDepth = maxDepth; 15 } 16 17 void traverse( SmbFile f, int depth ) throws MalformedURLException , IOException { 18 19 if( depth == 0 ) { 20 return; 21 } 22 23 SmbFile[] l = f.listFiles(); 24 25 for(int i = 0; l != null && i < l.length; i++ ) { 26 try { 27 for( int j = maxDepth - depth; j > 0; j-- ) { 28 System.out.print( " " ); 29 } 30 System.out.println( l[i] + " " + l[i].exists() ); 31 if( l[i].isDirectory() ) { 32 traverse( l[i], depth - 1 ); 33 } 34 } catch( IOException ioe ) { 35 System.out.println( l[i] + ":" ); 36 ioe.printStackTrace( System.out ); 37 } 38 } 39 } 40 41 public void run() { 42 try { 43 traverse( f, maxDepth ); 44 } catch( Exception ex ) { 45 ex.printStackTrace(); 46 } 47 } 48 49 public static void main(String [] argv) throws Exception { 50 if (argv.length < 3) { 51 System.err.println( "CrawlTest <url> <numthreads> <maxdepth>" ); 52 return; 53 } 54 55 SmbFile f = new SmbFile( argv[0] ); 56 int numThreads = Integer.parseInt( argv[1] ); 57 int maxDepth = Integer.parseInt( argv[2] ); 58 59 while (numThreads-- > 0 && System.in.read() == '\n') { 60 CrawlTest sc = new CrawlTest( f, maxDepth ); 61 sc.start(); 62 } 63 } 64 } 65 | Popular Tags |