KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > VerifyReads


1 import java.net.MalformedURLException JavaDoc;
2 import jcifs.smb.*;
3 import java.io.*;
4
5 public class VerifyReads {
6
7     int maxDepth;
8     byte[] buf = new byte[8192];
9
10     VerifyReads( int maxDepth ) {
11         this.maxDepth = maxDepth;
12     }
13
14     void mkdir( File dir ) {
15         if( dir != null && !dir.exists() ) {
16             mkdir( dir.getParentFile() );
17             dir.mkdir();
18         }
19     }
20
21     void copy( SmbFile f, String JavaDoc path, int depth ) throws MalformedURLException JavaDoc, IOException {
22         int i, d;
23         File localFile, dir;
24         SmbFile[] list;
25
26         if( depth == 0 ) {
27             return;
28         }
29
30         localFile = new File( path + "/" + f.getName() );
31         d = f.getName().lastIndexOf( '.' );
32
33         if( f.isDirectory() ) {
34
35             list = f.listFiles();
36
37             for( i = 0; i < list.length; i++ ) {
38                 copy( list[i], path + "/" + f.getName(), depth - 1 );
39             }
40         } else if( d > 1 && f.getName().substring( d ).equalsIgnoreCase( ".ini" )) {
41
42             mkdir( new File( path ));
43
44             SmbFileInputStream in = new SmbFileInputStream( f );
45             FileOutputStream out = new FileOutputStream( localFile );
46
47             while(( i = in.read( buf )) > 0 ) {
48                 out.write( buf, 0, i );
49             }
50
51             in.close();
52             out.close();
53         }
54     }
55
56     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
57         VerifyReads cd;
58         SmbFile top;
59         int depth;
60
61         if( argv.length < 2 ) {
62             System.err.println( "Must specify ini directory location (e.g. smb://mydom\\;user:pass@nyc-19b9/apps) followd by the maximum traversal depth");
63             System.exit( 1 );
64         }
65
66         depth = Integer.parseInt( argv[1] );
67         cd = new VerifyReads( depth );
68         top = new SmbFile( argv[0] );
69
70         if( !top.isDirectory() ) {
71             System.err.println( "The path specified is not a directory" );
72             System.exit( 1 );
73         }
74
75         cd.copy( top, ".", depth );
76     }
77 }
78
79
Popular Tags