File: CrawlTest.java

package info (click to toggle)
jcifs 1.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,856 kB
  • sloc: java: 23,124; xml: 3,663; ansic: 386; sh: 170; makefile: 26
file content (64 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import jcifs.smb.SmbFile;
import java.util.LinkedList;
import java.util.ListIterator;
import java.net.MalformedURLException;
import java.io.IOException;

public class CrawlTest extends Thread {

    SmbFile f;
    int maxDepth;

    CrawlTest( SmbFile f, int maxDepth ) {
        this.f = f;
        this.maxDepth = maxDepth;
    }

    void traverse( SmbFile f, int depth ) throws MalformedURLException, IOException {

        if( depth == 0 ) {
            return;
        }

        SmbFile[] l = f.listFiles();

        for(int i = 0; l != null && i < l.length; i++ ) {
            try {
                for( int j = maxDepth - depth; j > 0; j-- ) {
                    System.out.print( "    " );
                }
                System.out.println( l[i] + " " + l[i].exists() );
                if( l[i].isDirectory() ) {
                    traverse( l[i], depth - 1 );
                }
            } catch( IOException ioe ) {
                System.out.println( l[i] + ":" );
                ioe.printStackTrace( System.out );
            }
        }
    }

    public void run() {
        try {
            traverse( f, maxDepth );
        } catch( Exception ex ) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] argv) throws Exception {
        if (argv.length < 3) {
            System.err.println( "CrawlTest <url> <numthreads> <maxdepth>" );
            return;
        }

        SmbFile f = new SmbFile( argv[0] );
        int numThreads = Integer.parseInt( argv[1] );
        int maxDepth = Integer.parseInt( argv[2] );

        while (numThreads-- > 0 && System.in.read() == '\n') {
            CrawlTest sc = new CrawlTest( f, maxDepth );
            sc.start();
        }
    }
}