KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > VerifyIO


1 import java.net.MalformedURLException JavaDoc;
2 import jcifs.smb.*;
3 import java.io.*;
4
5 public class VerifyIO {
6
7     static File get( SmbFile f0 ) throws Exception JavaDoc {
8         int i;
9         File f1;
10         byte[] buf = new byte[8192];
11
12         f1 = new File( f0.getName() );
13         FileOutputStream out = new FileOutputStream( f1 );
14         SmbFileInputStream in = new SmbFileInputStream( f0 );
15
16         while(( i = in.read( buf )) > 0 ) {
17             out.write( buf, 0, i );
18             System.err.print( '.' );
19         }
20
21         in.close();
22         out.close();
23
24         return f1;
25     }
26     static void put( SmbFile f2 ) throws Exception JavaDoc {
27         int i;
28         byte[] buf = new byte[8192];
29
30         FileInputStream in = new FileInputStream( f2.getName() );
31         SmbFileOutputStream out = new SmbFileOutputStream( f2 );
32
33         while(( i = in.read( buf )) > 0 ) {
34             out.write( buf, 0, i );
35             System.err.print( '-' );
36         }
37
38         in.close();
39         out.close();
40     }
41
42     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
43         BufferedReader in;
44         String JavaDoc name;
45
46         if( argv.length < 2 ) {
47             System.err.println( "Must provide file of SMB URLs and destination directory" );
48             System.exit( 1 );
49         }
50
51         in = new BufferedReader( new FileReader( argv[0] ));
52         while(( name = in.readLine() ) != null ) {
53             SmbFile f0, f2;
54             File f1;
55
56             System.err.print( name + ": " );
57             f0 = new SmbFile( name );
58             f1 = get( f0 );
59
60             if( f0.length() != f1.length() ) {
61                 throw new RuntimeException JavaDoc( "File lengths do not match: f0=" + f0.length() + ",f1=" + f1.length() );
62             }
63
64             f2 = new SmbFile( argv[1] + "/" + f0.getName() );
65             put( f2 );
66
67             if( f1.length() != f2.length() ) {
68                 throw new RuntimeException JavaDoc( "File lengths do not match: f1=" + f1.length() + ",f2=" + f2.length() );
69             }
70
71             f1.delete();
72             System.err.println( " ok" );
73         }
74     }
75 }
76
77
Popular Tags