1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  package org.newsclub.net.unix;
19  
20  import java.io.Closeable;
21  import java.io.IOException;
22  import java.net.SocketException;
23  import java.nio.channels.ClosedByInterruptException;
24  
25  import org.eclipse.jdt.annotation.NonNull;
26  
27  
28  
29  
30  
31  
32  final class SocketClosedByInterruptException extends SocketClosedException {
33    private static final long serialVersionUID = 1L;
34  
35    
36  
37  
38    private SocketClosedByInterruptException() {
39      super("Closed by interrupt");
40    }
41  
42    static SocketClosedByInterruptException newInstanceAndClose(Closeable closeable) {
43      Throwable suppressed = null;
44      try {
45        if (closeable != null) {
46          closeable.close();
47        }
48      } catch (RuntimeException | IOException e) {
49        suppressed = e;
50      }
51      SocketClosedByInterruptException exc = new SocketClosedByInterruptException();
52      if (suppressed != null) {
53        exc.addSuppressed(suppressed);
54      }
55      return exc;
56    }
57  
58    public @NonNull ClosedByInterruptException asClosedByInterruptException() {
59      ClosedByInterruptException exc = new ClosedByInterruptException();
60      exc.initCause(this);
61      return exc;
62    }
63  }