File: InterruptTest.java

package info (click to toggle)
jcifs 1.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,856 kB
  • sloc: java: 23,124; xml: 3,663; ansic: 386; sh: 170; makefile: 26
file content (54 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (7)
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
import java.io.InterruptedIOException;
import jcifs.util.transport.TransportException;
import jcifs.smb.*;

public class InterruptTest extends Thread {

    String url;

    public InterruptTest(String url) {
        this.url = url;
    }
    public void run() {
        for (int i = 0; i < 100; i++) {
            try {
                SmbFileInputStream in = new SmbFileInputStream(url);

                byte[] b = new byte[10];
                while(in.read( b ) > 0) {
                    ;
                }

                in.close();
            } catch(InterruptedIOException iioe) {
                System.out.println("InterruptedIOException");
                continue;
            } catch(SmbException se) {
                Throwable t = se.getRootCause();
                if (t instanceof TransportException) {
                    TransportException te = (TransportException)t;
                    t = te.getRootCause();
                    if (t instanceof InterruptedException) {
                        System.out.println("InterruptedException in constructor");
                        continue;
                    }
                }
                se.printStackTrace();
                try { Thread.sleep(500); } catch(InterruptedException ie) {}
            } catch(Exception e) {
                e.printStackTrace();
                break;
            }
        }
    }

    public static void main( String argv[] ) throws Exception {
        InterruptTest it = new InterruptTest(argv[0]);
        it.start();
        for (int i = 0; i < 20; i++) {
            Thread.sleep(200);
            it.interrupt();
        }
    }
}