1 | /** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
3 | * or more contributor license agreements. See the NOTICE file |
---|
4 | * distributed with this work for additional information |
---|
5 | * regarding copyright ownership. The ASF licenses this file |
---|
6 | * to you under the Apache License, Version 2.0 (the |
---|
7 | * "License"); you may not use this file except in compliance |
---|
8 | * with the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | package org.apache.hadoop.mapreduce.lib.input; |
---|
19 | |
---|
20 | import java.io.IOException; |
---|
21 | import java.util.List; |
---|
22 | import java.util.Iterator; |
---|
23 | |
---|
24 | /** |
---|
25 | * This class wraps a list of problems with the input, so that the user |
---|
26 | * can get a list of problems together instead of finding and fixing them one |
---|
27 | * by one. |
---|
28 | */ |
---|
29 | public class InvalidInputException extends IOException { |
---|
30 | private static final long serialVersionUID = -380668190578456802L; |
---|
31 | private List<IOException> problems; |
---|
32 | |
---|
33 | /** |
---|
34 | * Create the exception with the given list. |
---|
35 | * @param probs the list of problems to report. this list is not copied. |
---|
36 | */ |
---|
37 | public InvalidInputException(List<IOException> probs) { |
---|
38 | problems = probs; |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * Get the complete list of the problems reported. |
---|
43 | * @return the list of problems, which must not be modified |
---|
44 | */ |
---|
45 | public List<IOException> getProblems() { |
---|
46 | return problems; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Get a summary message of the problems found. |
---|
51 | * @return the concatenated messages from all of the problems. |
---|
52 | */ |
---|
53 | public String getMessage() { |
---|
54 | StringBuffer result = new StringBuffer(); |
---|
55 | Iterator<IOException> itr = problems.iterator(); |
---|
56 | while(itr.hasNext()) { |
---|
57 | result.append(itr.next().getMessage()); |
---|
58 | if (itr.hasNext()) { |
---|
59 | result.append("\n"); |
---|
60 | } |
---|
61 | } |
---|
62 | return result.toString(); |
---|
63 | } |
---|
64 | } |
---|