src/java.base/share/classes/sun/net/www/MeteredStream.java
author dfuchs
Fri, 30 Aug 2019 15:42:27 +0100
branchJDK-8229867-branch
changeset 57968 8595871a5446
parent 47216 71c04702a3d5
permissions -rw-r--r--
JDK-8229867: first prototype
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
     2
 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net.www;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
    29
import java.util.concurrent.locks.ReentrantLock;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.net.ProgressSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.net.www.http.ChunkedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class MeteredStream extends FilterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    // Instance variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /* if expected != -1, after we've read >= expected, we're "closed" and return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * from subsequest read() 's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    protected boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    protected long expected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected long count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected long markedCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected int markLimit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    protected ProgressSource pi;
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
    46
    protected final ReentrantLock readLock = new ReentrantLock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public MeteredStream(InputStream is, ProgressSource pi, long expected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        this.pi = pi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        this.expected = expected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (pi != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            pi.updateProgress(0, expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
    60
    private final  void justRead(long n) throws IOException   {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
    61
        assert readLock.isHeldByCurrentThread();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
             * don't close automatically when mark is set and is valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
             * cannot reset() after close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (!isMarked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        count += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         * If read beyond the markLimit, invalidate the mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (count - markedCount > markLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            markLimit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (pi != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            pi.updateProgress(count, expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (isMarked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // if expected length is known, we could determine if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // read overrun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (expected > 0)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (count >= expected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Returns true if the mark is valid, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private boolean isMarked() {
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   104
        assert readLock.isHeldByCurrentThread();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (markLimit < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // mark is set, but is not valid anymore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (count - markedCount > markLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
           return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // mark still holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   119
    public int read() throws java.io.IOException {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   120
        if (closed) return -1;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   121
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   122
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   123
            if (closed) return -1;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   124
            int c = in.read();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   125
            if (c != -1) {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   126
                justRead(1);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   127
            } else {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   128
                justRead(c);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   129
            }
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   130
            return c;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   131
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   132
            readLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   136
    public int read(byte b[], int off, int len)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                throws java.io.IOException {
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   138
        if (closed) return -1;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   139
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   140
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   141
            if (closed) return -1;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   142
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   143
            int n = in.read(b, off, len);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   144
            justRead(n);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   145
            return n;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   146
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   147
            readLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   151
    public long skip(long n) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   153
        if (closed) return 0;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   154
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   155
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   156
            // REMIND: what does skip do on EOF????
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   157
            if (closed) return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   159
            if (in instanceof ChunkedInputStream) {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   160
                n = in.skip(n);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   161
            } else {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   162
                // just skip min(n, num_bytes_left)
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   163
                long min = (n > expected - count) ? expected - count : n;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   164
                n = in.skip(min);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   165
            }
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   166
            justRead(n);
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   167
            return n;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   168
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   169
            readLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public void close() throws IOException {
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   174
        if (closed) return;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   175
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   176
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   177
            if (closed) return;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   178
            if (pi != null)
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   179
                pi.finishTracking();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   180
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   181
            closed = true;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   182
            in.close();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   183
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   184
            readLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   188
    public int available() throws IOException {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   189
        if (closed) return 0;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   190
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   191
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   192
            return closed ? 0 : in.available();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   193
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   194
            readLock.unlock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   195
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   198
    public void mark(int readLimit) {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   199
        if (closed) return;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   200
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   201
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   202
            if (closed) return;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   203
            super.mark(readLimit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   205
            /*
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   206
             * mark the count to restore upon reset
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   207
             */
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   208
            markedCount = count;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   209
            markLimit = readLimit;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   210
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   211
            readLock.unlock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   212
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   215
    public void reset() throws IOException {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   216
        if (closed) return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   218
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   219
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   220
            if (closed) return;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   221
            if (!isMarked()) {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   222
                throw new IOException("Resetting to an invalid mark");
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   223
            }
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   224
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   225
            count = markedCount;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   226
            super.reset();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   227
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   228
            readLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public boolean markSupported() {
57968
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   233
        if (closed) return false;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   234
        readLock.lock();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   235
        try {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   236
            if (closed) return false;
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   237
            return super.markSupported();
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   238
        } finally {
8595871a5446 JDK-8229867: first prototype
dfuchs
parents: 47216
diff changeset
   239
            readLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
44534
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 25859
diff changeset
   243
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected void finalize() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (pi != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                pi.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            // Call super class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            super.finalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}