1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.core.write;
21
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.LinkedHashMap;
27 import java.util.List;
28 import java.util.Set;
29
30 import org.apache.mina.util.MapBackedSet;
31
32
33
34
35
36
37 public class WriteException extends IOException {
38
39 private static final long serialVersionUID = -4174407422754524197L;
40
41
42 private final List<WriteRequest> requests;
43
44
45
46
47
48
49 public WriteException(WriteRequest request) {
50 super();
51 this.requests = asRequestList(request);
52 }
53
54
55
56
57
58
59
60 public WriteException(WriteRequest request, String message) {
61 super(message);
62 this.requests = asRequestList(request);
63 }
64
65
66
67
68
69
70
71
72 public WriteException(WriteRequest request, String message, Throwable cause) {
73 super(message);
74 initCause(cause);
75 this.requests = asRequestList(request);
76 }
77
78
79
80
81
82
83
84 public WriteException(WriteRequest request, Throwable cause) {
85 initCause(cause);
86 this.requests = asRequestList(request);
87 }
88
89
90
91
92
93
94 public WriteException(Collection<WriteRequest> requests) {
95 super();
96 this.requests = asRequestList(requests);
97 }
98
99
100
101
102
103
104
105 public WriteException(Collection<WriteRequest> requests, String message) {
106 super(message);
107 this.requests = asRequestList(requests);
108 }
109
110
111
112
113
114
115
116
117 public WriteException(Collection<WriteRequest> requests, String message, Throwable cause) {
118 super(message);
119 initCause(cause);
120 this.requests = asRequestList(requests);
121 }
122
123
124
125
126
127
128
129 public WriteException(Collection<WriteRequest> requests, Throwable cause) {
130 initCause(cause);
131 this.requests = asRequestList(requests);
132 }
133
134
135
136
137 public List<WriteRequest> getRequests() {
138 return requests;
139 }
140
141
142
143
144 public WriteRequest getRequest() {
145 return requests.get(0);
146 }
147
148 private static List<WriteRequest> asRequestList(Collection<WriteRequest> requests) {
149 if (requests == null) {
150 throw new IllegalArgumentException("requests");
151 }
152
153 if (requests.isEmpty()) {
154 throw new IllegalArgumentException("requests is empty.");
155 }
156
157
158 Set<WriteRequest> newRequests = new MapBackedSet<WriteRequest>(new LinkedHashMap<WriteRequest, Boolean>());
159
160 for (WriteRequest r : requests) {
161 newRequests.add(r.getOriginalRequest());
162 }
163
164 return Collections.unmodifiableList(new ArrayList<WriteRequest>(newRequests));
165 }
166
167 private static List<WriteRequest> asRequestList(WriteRequest request) {
168 if (request == null) {
169 throw new IllegalArgumentException("request");
170 }
171
172 List<WriteRequest> requests = new ArrayList<WriteRequest>(1);
173 requests.add(request.getOriginalRequest());
174
175 return Collections.unmodifiableList(requests);
176 }
177 }