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