KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TransactNamedPipe


1 import jcifs.smb.SmbNamedPipe;
2 import java.io.InputStream JavaDoc;
3 import java.io.OutputStream JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.FileOutputStream JavaDoc;
6
7 public class TransactNamedPipe {
8
9     public static void main( String JavaDoc[] argv ) throws Exception JavaDoc {
10
11         if( argv.length < 2 ) {
12             throw new IllegalArgumentException JavaDoc(
13                         "args: <smburl> <filedatatosend> <filetowriterecvdata>" );
14         }
15
16         byte[] b = new byte[65535];
17         FileInputStream JavaDoc fin = new FileInputStream JavaDoc( argv[1] );
18         FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc( argv[2] );
19
20         SmbNamedPipe pipe = new SmbNamedPipe( argv[0],
21                 SmbNamedPipe.PIPE_TYPE_RDWR | SmbNamedPipe.PIPE_TYPE_TRANSACT );
22         OutputStream JavaDoc out = pipe.getNamedPipeOutputStream();
23         InputStream JavaDoc in = pipe.getNamedPipeInputStream();
24
25         int n = fin.read( b );
26         System.out.println( "writing " + n + " bytes" );
27         out.write( b, 0, n );
28         n = in.read(b);
29         System.out.println( "read " + n + " bytes" );
30         fos.write(b, 0, n );
31
32         fin.close();
33         fos.close();
34         out.close();
35     }
36 }
37
Popular Tags