KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > go > trove > net > CheckedInterruptedIOException


1 /*
2  * CheckedInterruptedIOException.java
3  *
4  * Copyright (c) 2000 Walt Disney Internet Group. All Rights Reserved.
5  *
6  * Original author: Brian S O'Neill
7  *
8  * $Workfile:: CheckedInterruptedIOException.java $
9  * $Author:: Briano $
10  * $Revision:: 2 $
11  * $Date:: 01/01/22 8:11p $
12  */

13
14 package com.go.trove.net;
15
16 import java.io.*;
17 import java.net.*;
18 import java.lang.ref.*;
19
20 /******************************************************************************
21  *
22  * @author Brian S O'Neill
23  * @version
24  * <!--$$Revision:--> 2 <!-- $-->, <!--$$JustDate:--> 01/01/22 <!-- $-->
25  */

26 public class CheckedInterruptedIOException extends InterruptedIOException {
27     static CheckedInterruptedIOException create
28         (InterruptedIOException cause, Socket source) {
29         if (cause instanceof CheckedInterruptedIOException) {
30             return (CheckedInterruptedIOException)cause;
31         }
32         else {
33             return new CheckedInterruptedIOException(cause, source);
34         }
35     }
36
37     private InterruptedIOException mCause;
38     private String JavaDoc mMessagePrefix;
39     private Reference mSource;
40
41     private CheckedInterruptedIOException(InterruptedIOException cause,
42                                           Socket source) {
43         this(cause, source, cause.getMessage());
44     }
45
46     private CheckedInterruptedIOException(InterruptedIOException cause,
47                                           Socket source, String JavaDoc message) {
48         super(CheckedSocketException.createMessagePrefix(source) +
49               ' ' + message);
50         mCause = cause;
51         mMessagePrefix = CheckedSocketException.createMessagePrefix(source);
52         mSource = new WeakReference(source);
53     }
54
55     public InterruptedIOException getCause() {
56         return mCause;
57     }
58
59     /**
60      * Returns null if source socket has been reclaimed by the garbage
61      * collector.
62      */

63     public Socket getSource() {
64         return (Socket)mSource.get();
65     }
66
67     public void printStackTrace() {
68         printStackTrace(System.err);
69     }
70
71     public void printStackTrace(PrintStream ps) {
72         synchronized (ps) {
73             ps.print(mMessagePrefix);
74             ps.print(": ");
75             mCause.printStackTrace(ps);
76         }
77     }
78
79     public void printStackTrace(PrintWriter pw) {
80         synchronized (pw) {
81             pw.print(mMessagePrefix);
82             pw.print(": ");
83             mCause.printStackTrace(pw);
84         }
85     }
86 }
87
Popular Tags