src/java.base/share/classes/java/io/CharArrayReader.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58288 48e480e56aad
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 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 java.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This class implements a character buffer that can be used as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * character-input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author      Herb Jellinek
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 5506
diff changeset
    33
 * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class CharArrayReader extends Reader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    /** The character buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    protected char buf[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /** The current buffer position. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    protected int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /** The position of mark in buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected int markedPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *  The index of the end of this buffer.  There is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *  data at or beyond this index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Creates a CharArrayReader from the specified array of chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param buf       Input buffer (not copied)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public CharArrayReader(char buf[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.buf = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.count = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Creates a CharArrayReader from the specified array of chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * <p> The resulting reader will start reading at the given
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 30443
diff changeset
    65
     * {@code offset}.  The total number of {@code char} values that can be
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 30443
diff changeset
    66
     * read from this reader will be either {@code length} or
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 30443
diff changeset
    67
     * {@code buf.length-offset}, whichever is smaller.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @throws IllegalArgumentException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 30443
diff changeset
    70
     *         If {@code offset} is negative or greater than
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 30443
diff changeset
    71
     *         {@code buf.length}, or if {@code length} is negative, or if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *         the sum of these two values is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param buf       Input buffer (not copied)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param offset    Offset of the first char to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param length    Number of chars to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public CharArrayReader(char buf[], int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if ((offset < 0) || (offset > buf.length) || (length < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            ((offset + length) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.buf = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.pos = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.count = Math.min(offset + length, buf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        this.markedPos = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /** Checks to make sure that the stream has not been closed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (buf == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Reads a single character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
    98
     * @throws      IOException  If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (pos >= count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                return buf[pos++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Reads characters into a portion of an array.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   112
     * @param   b  Destination buffer
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   113
     * @param   off  Offset at which to start storing characters
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   114
     * @param   len   Maximum number of characters to read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return  The actual number of characters read, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *          the end of the stream has been reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   118
     * @throws  IOException  If an I/O error occurs
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   119
     * @throws  IndexOutOfBoundsException {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public int read(char b[], int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if ((off < 0) || (off > b.length) || (len < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                ((off + len) > b.length) || ((off + len) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (pos >= count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
40263
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   134
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   135
            int avail = count - pos;
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   136
            if (len > avail) {
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   137
                len = avail;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (len <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            System.arraycopy(buf, pos, b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            pos += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Skips characters.  Returns the number of characters that were skipped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   151
     * <p>The {@code n} parameter may be negative, even though the
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   152
     * {@code skip} method of the {@link Reader} superclass throws
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   153
     * an exception in this case. If {@code n} is negative, then
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   154
     * this method does nothing and returns {@code 0}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   156
     * @param      n The number of characters to skip
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   157
     * @return     The number of characters actually skipped
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   158
     * @throws     IOException If the stream is closed, or an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public long skip(long n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            ensureOpen();
40263
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   163
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   164
            long avail = count - pos;
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   165
            if (n > avail) {
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents: 34694
diff changeset
   166
                n = avail;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (n < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            pos += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Tells whether this stream is ready to be read.  Character-array readers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * are always ready to be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   180
     * @throws     IOException  If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public boolean ready() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return (count - pos) > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Tells whether this stream supports the mark() operation, which it does.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public boolean markSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Marks the present position in the stream.  Subsequent calls to reset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * will reposition the stream to this point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param  readAheadLimit  Limit on the number of characters that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *                         read while still preserving the mark.  Because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *                         the stream's input comes from a character array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *                         there is no actual limit; hence this argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *                         ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   206
     * @throws     IOException  If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public void mark(int readAheadLimit) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            markedPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Resets the stream to the most recent mark, or to the beginning if it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * never been marked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   219
     * @throws     IOException  If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void reset() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            pos = markedPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Closes the stream and releases any system resources associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * it.  Once the stream has been closed, further read(), ready(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * mark(), reset(), or skip() invocations will throw an IOException.
34694
8566f3f715b0 8143394: PushbackReader throws NullPointerException
bpb
parents: 32033
diff changeset
   232
     * Closing a previously closed stream has no effect. This method will block
8566f3f715b0 8143394: PushbackReader throws NullPointerException
bpb
parents: 32033
diff changeset
   233
     * while there is another thread blocking on the reader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void close() {
34694
8566f3f715b0 8143394: PushbackReader throws NullPointerException
bpb
parents: 32033
diff changeset
   236
        synchronized (lock) {
8566f3f715b0 8143394: PushbackReader throws NullPointerException
bpb
parents: 32033
diff changeset
   237
            buf = null;
8566f3f715b0 8143394: PushbackReader throws NullPointerException
bpb
parents: 32033
diff changeset
   238
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
}