    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 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.commons.compress.archivers;
    020
    021import java.util.function.Supplier;
    022
    023import org.apache.commons.compress.CompressException;
    024
    025/**
    026 * Signals that an Archive exception of some sort has occurred.
    027 */
    028public class ArchiveException extends CompressException {
    029
    030    /** Serial. */
    031    private static final long serialVersionUID = 2772690708123267100L;
    032
    033    /**
    034     * Checks that the specified object reference is not {@code null} and throws a customized {@link ArchiveException} if it is. *
    035     *
    036     * @param obj             the object reference to check for nullity.
    037     * @param messageSupplier supplier of the detail message to be used in the event that a {@code ArchiveException} is thrown
    038     * @param <T>             the type of the reference.
    039     * @return {@code obj} if not {@code null}
    040     * @throws ArchiveException if {@code obj} is {@code null}
    041     * @since 1.28.0
    042     */
    043    public static <T> T requireNonNull(final T obj, final Supplier<String> messageSupplier) throws ArchiveException {
    044        return CompressException.requireNonNull(ArchiveException.class, obj, messageSupplier);
    045    }
    046
    047    /**
    048     * Constructs an {@code ArchiveException} with {@code null} as its error detail message.
    049     *
    050     * @since 1.28.0
    051     */
    052    public ArchiveException() {
    053        // empty
    054    }
    055
    056    /**
    057     * Constructs a new exception with the specified detail message. The cause is not initialized.
    058     *
    059     * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
    060     */
    061    public ArchiveException(final String message) {
    062        super(message);
    063    }
    064
    065    /**
    066     * Constructs a new exception with the specified detail message and cause.
    067     *
    068     * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
    069     * @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
    070     *                unknown.
    071     * @deprecated Use {@link #ArchiveException(String, Throwable)}.
    072     */
    073    @Deprecated
    074    public ArchiveException(final String message, final Exception cause) {
    075        super(message, cause);
    076    }
    077
    078    /**
    079     * Constructs a new exception with the specified detail message and cause.
    080     *
    081     * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
    082     * @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
    083     *                unknown.
    084     * @since 1.28.0
    085     */
    086    public ArchiveException(final String message, final Throwable cause) {
    087        super(message, cause);
    088    }
    089
    090    /**
    091     * Constructs a {@code ArchiveException} with the specified cause and a detail message.
    092     *
    093     * @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
    094     *              is nonexistent or unknown.)
    095     * @since 1.28.0
    096     */
    097    public ArchiveException(final Throwable cause) {
    098        super(cause);
    099    }
    100}