KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > CallNamedPipe


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