CloseableConsumer.java

  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.  * http://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.examples;

  20. import java.io.Closeable;
  21. import java.io.IOException;

  22. /**
  23.  * Callback that is informed about a closable resource that has been wrapped around a passed in stream or channel by Expander or Archiver when Expander or
  24.  * Archiver no longer need them.
  25.  *
  26.  * <p>
  27.  * This provides a way to close said resources in the calling code.
  28.  * </p>
  29.  *
  30.  * @since 1.19
  31.  */
  32. public interface CloseableConsumer {

  33.     /**
  34.      * Closes the passed in Closeable immediately.
  35.      */
  36.     CloseableConsumer CLOSING_CONSUMER = Closeable::close;

  37.     /**
  38.      * Ignores the passed in Closeable.
  39.      */
  40.     CloseableConsumer NULL_CONSUMER = c -> {
  41.     };

  42.     /**
  43.      * Callback that is informed about a Closeable resource that has been wrapped around a passed in stream or channel by Expander or Archiver when Expander or
  44.      * Archiver no longer need them.
  45.      *
  46.      * @param c Closeable created by Expander or Archiver that is now no longer used
  47.      *
  48.      * @throws IOException on error
  49.      */
  50.     void accept(Closeable c) throws IOException;
  51. }