1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.tika.io; 18 19 import java.io.IOException; 20 21 /** 22 * An {@link IOException} wrapper that tags the wrapped exception with 23 * a given object reference. Both the tag and the wrapped original exception 24 * can be used to determine further processing when this exception is caught. 25 */ 26 public class TaggedIOException extends IOExceptionWithCause { 27 28 /** 29 * The object reference used to tag the exception. 30 */ 31 private final Object tag; 32 33 /** 34 * Creates a tagged wrapper for the given exception. 35 * 36 * @param original the exception to be tagged 37 * @param tag tag object 38 */ 39 public TaggedIOException(IOException original, Object tag) { 40 super(original.getMessage(), original); 41 this.tag = tag; 42 } 43 44 /** 45 * Returns the object reference used as the tag this exception. 46 * 47 * @return tag object 48 */ 49 public Object getTag() { 50 return tag; 51 } 52 53 /** 54 * Returns the wrapped exception. The only difference to the overridden 55 * {@link Throwable#getCause()} method is the narrower return type. 56 * 57 * @return wrapped exception 58 */ 59 @Override 60 public IOException getCause() { 61 return (IOException) super.getCause(); 62 } 63 64 }