View Javadoc
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   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.archivers;
20  
21  import java.util.function.Supplier;
22  
23  import org.apache.commons.compress.CompressException;
24  
25  /**
26   * Signals that an Archive exception of some sort has occurred.
27   */
28  public class ArchiveException extends CompressException {
29  
30      /** Serial. */
31      private static final long serialVersionUID = 2772690708123267100L;
32  
33      /**
34       * Checks that the specified object reference is not {@code null} and throws a customized {@link ArchiveException} if it is. *
35       *
36       * @param obj             the object reference to check for nullity.
37       * @param messageSupplier supplier of the detail message to be used in the event that a {@code ArchiveException} is thrown
38       * @param <T>             the type of the reference.
39       * @return {@code obj} if not {@code null}
40       * @throws ArchiveException if {@code obj} is {@code null}
41       * @since 1.28.0
42       */
43      public static <T> T requireNonNull(final T obj, final Supplier<String> messageSupplier) throws ArchiveException {
44          return CompressException.requireNonNull(ArchiveException.class, obj, messageSupplier);
45      }
46  
47      /**
48       * Constructs an {@code ArchiveException} with {@code null} as its error detail message.
49       *
50       * @since 1.28.0
51       */
52      public ArchiveException() {
53          // empty
54      }
55  
56      /**
57       * Constructs a new exception with the specified detail message. The cause is not initialized.
58       *
59       * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
60       */
61      public ArchiveException(final String message) {
62          super(message);
63      }
64  
65      /**
66       * Constructs a new exception with the specified detail message and cause.
67       *
68       * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
69       * @param cause   The cause (which is saved for later retrieval by the {@link #getCause()} method). A null value indicates that the cause is nonexistent or
70       *                unknown.
71       * @deprecated Use {@link #ArchiveException(String, Throwable)}.
72       */
73      @Deprecated
74      public ArchiveException(final String message, final Exception cause) {
75          super(message, cause);
76      }
77  
78      /**
79       * Constructs a new exception with the specified detail message and cause.
80       *
81       * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
82       * @param cause   The cause (which is saved for later retrieval by the {@link #getCause()} method). A null value indicates that the cause is nonexistent or
83       *                unknown.
84       * @since 1.28.0
85       */
86      public ArchiveException(final String message, final Throwable cause) {
87          super(message, cause);
88      }
89  
90      /**
91       * Constructs a {@code ArchiveException} with the specified cause and a detail message.
92       *
93       * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the cause
94       *              is nonexistent or unknown.)
95       * @since 1.28.0
96       */
97      public ArchiveException(final Throwable cause) {
98          super(cause);
99      }
100 }