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   * 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  
21  import java.io.Closeable;
22  import java.io.IOException;
23  
24  /**
25   * 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
26   * Archiver no longer need them.
27   *
28   * <p>
29   * This provides a way to close said resources in the calling code.
30   * </p>
31   *
32   * @since 1.19
33   */
34  public interface CloseableConsumer {
35  
36      /**
37       * Closes the passed in Closeable immediately.
38       */
39      CloseableConsumer CLOSING_CONSUMER = Closeable::close;
40  
41      /**
42       * Ignores the passed in Closeable.
43       */
44      CloseableConsumer NULL_CONSUMER = c -> {
45      };
46  
47      /**
48       * 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
49       * Archiver no longer need them.
50       *
51       * @param c Closeable created by Expander or Archiver that is now no longer used
52       *
53       * @throws IOException on error
54       */
55      void accept(Closeable c) throws IOException;
56  }