001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.mapreduce.lib.input;
019
020import java.io.IOException;
021import java.util.List;
022import java.util.Iterator;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026
027/**
028 * This class wraps a list of problems with the input, so that the user
029 * can get a list of problems together instead of finding and fixing them one 
030 * by one.
031 */
032@InterfaceAudience.Public
033@InterfaceStability.Stable
034public class InvalidInputException extends IOException {
035  private static final long serialVersionUID = -380668190578456802L;
036  private List<IOException> problems;
037  
038  /**
039   * Create the exception with the given list.
040   * @param probs the list of problems to report. this list is not copied.
041   */
042  public InvalidInputException(List<IOException> probs) {
043    problems = probs;
044  }
045  
046  /**
047   * Get the complete list of the problems reported.
048   * @return the list of problems, which must not be modified
049   */
050  public List<IOException> getProblems() {
051    return problems;
052  }
053  
054  /**
055   * Get a summary message of the problems found.
056   * @return the concatenated messages from all of the problems.
057   */
058  public String getMessage() {
059    StringBuffer result = new StringBuffer();
060    Iterator<IOException> itr = problems.iterator();
061    while(itr.hasNext()) {
062      result.append(itr.next().getMessage());
063      if (itr.hasNext()) {
064        result.append("\n");
065      }
066    }
067    return result.toString();
068  }
069}