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 */
018 package org.apache.hadoop.io;
019
020 import java.io.IOException;
021 import java.util.List;
022
023 import org.apache.hadoop.classification.InterfaceAudience;
024 import org.apache.hadoop.classification.InterfaceStability;
025
026 /** Encapsulate a list of {@link IOException} into an {@link IOException} */
027 @InterfaceAudience.Public
028 @InterfaceStability.Stable
029 public class MultipleIOException extends IOException {
030 /** Require by {@link java.io.Serializable} */
031 private static final long serialVersionUID = 1L;
032
033 private final List<IOException> exceptions;
034
035 /** Constructor is private, use {@link #createIOException(List)}. */
036 private MultipleIOException(List<IOException> exceptions) {
037 super(exceptions.size() + " exceptions " + exceptions);
038 this.exceptions = exceptions;
039 }
040
041 /** @return the underlying exceptions */
042 public List<IOException> getExceptions() {return exceptions;}
043
044 /** A convenient method to create an {@link IOException}. */
045 public static IOException createIOException(List<IOException> exceptions) {
046 if (exceptions == null || exceptions.isEmpty()) {
047 return null;
048 }
049 if (exceptions.size() == 1) {
050 return exceptions.get(0);
051 }
052 return new MultipleIOException(exceptions);
053 }
054 }