jdk/src/share/classes/java/util/stream/CloseableStream.java
changeset 20145 08266da0533a
parent 20144 f998f8dc5b40
parent 19945 74049f7a28b4
child 20146 019d103c3e40
equal deleted inserted replaced
20144:f998f8dc5b40 20145:08266da0533a
     1 /*
       
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package java.util.stream;
       
    27 
       
    28 /**
       
    29  * A {@code CloseableStream} is a {@code Stream} that can be closed.
       
    30  * The close method is invoked to release resources that the object is
       
    31  * holding (such as open files).
       
    32  *
       
    33  * @param <T> The type of stream elements
       
    34  * @since 1.8
       
    35  */
       
    36 public interface CloseableStream<T> extends Stream<T>, AutoCloseable {
       
    37 
       
    38     /**
       
    39      * Closes this resource, relinquishing any underlying resources.
       
    40      * This method is invoked automatically on objects managed by the
       
    41      * {@code try}-with-resources statement.  Does nothing if called when
       
    42      * the resource has already been closed.
       
    43      *
       
    44      * This method does not allow throwing checked {@code Exception}s like
       
    45      * {@link AutoCloseable#close() AutoCloseable.close()}. Cases where the
       
    46      * close operation may fail require careful attention by implementers. It
       
    47      * is strongly advised to relinquish the underlying resources and to
       
    48      * internally <em>mark</em> the resource as closed. The {@code close}
       
    49      * method is unlikely to be invoked more than once and so this ensures
       
    50      * that the resources are released in a timely manner. Furthermore it
       
    51      * reduces problems that could arise when the resource wraps, or is
       
    52      * wrapped, by another resource.
       
    53      *
       
    54      * @see AutoCloseable#close()
       
    55      */
       
    56     void close();
       
    57 }