/usr/share/doc/libjcifs-java/examples/PeekNamedPipe.java is in libjcifs-java-doc 1.3.19-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | import jcifs.smb.SmbNamedPipe;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
public class PeekNamedPipe {
static class ReceiverThread extends Thread {
InputStream in;
byte[] buf = new byte[20];
int n;
ReceiverThread( InputStream in ) {
this.in = in;
}
public void run() {
try {
while( true ) {
while(( n = in.available() ) == 0 ) {
System.out.println( "0 available" );
sleep( 3000 );
}
System.out.println( n + " available" );
if(( n = in.read( buf )) == -1 ) {
break;
}
System.out.println( new String( buf, 0, n ));
}
} catch( Exception e ) {
e.printStackTrace();
}
System.out.println( "run finished" );
}
}
public static void main( String[] argv ) throws Exception {
SmbNamedPipe pipe = new SmbNamedPipe( argv[0], SmbNamedPipe.PIPE_TYPE_RDWR );
InputStream in = pipe.getNamedPipeInputStream();
OutputStream out = pipe.getNamedPipeOutputStream();
ReceiverThread rt = new ReceiverThread( in );
rt.start();
StringBuffer sb = new StringBuffer();
String msg;
int c;
while(( c = System.in.read() ) != -1 ) {
if( c == '\n' ) {
msg = sb.toString();
if( msg.startsWith( "exi" )) {
break;
}
out.write( msg.getBytes() );
sb.setLength( 0 );
} else {
sb.append( (char)c );
}
}
in.close();
out.close();
}
}
|