src/java.base/share/classes/java/io/StringReader.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 47216 71c04702a3d5
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    60      * Reads a single character.
    60      * Reads a single character.
    61      *
    61      *
    62      * @return     The character read, or -1 if the end of the stream has been
    62      * @return     The character read, or -1 if the end of the stream has been
    63      *             reached
    63      *             reached
    64      *
    64      *
    65      * @exception  IOException  If an I/O error occurs
    65      * @throws     IOException  If an I/O error occurs
    66      */
    66      */
    67     public int read() throws IOException {
    67     public int read() throws IOException {
    68         synchronized (lock) {
    68         synchronized (lock) {
    69             ensureOpen();
    69             ensureOpen();
    70             if (next >= length)
    70             if (next >= length)
    81      * @param      len   Maximum number of characters to read
    81      * @param      len   Maximum number of characters to read
    82      *
    82      *
    83      * @return     The number of characters read, or -1 if the end of the
    83      * @return     The number of characters read, or -1 if the end of the
    84      *             stream has been reached
    84      *             stream has been reached
    85      *
    85      *
    86      * @exception  IOException  If an I/O error occurs
    86      * @throws     IOException  If an I/O error occurs
    87      * @exception  IndexOutOfBoundsException {@inheritDoc}
    87      * @throws     IndexOutOfBoundsException {@inheritDoc}
    88      */
    88      */
    89     public int read(char cbuf[], int off, int len) throws IOException {
    89     public int read(char cbuf[], int off, int len) throws IOException {
    90         synchronized (lock) {
    90         synchronized (lock) {
    91             ensureOpen();
    91             ensureOpen();
    92             if ((off < 0) || (off > cbuf.length) || (len < 0) ||
    92             if ((off < 0) || (off > cbuf.length) || (len < 0) ||
   106 
   106 
   107     /**
   107     /**
   108      * Skips the specified number of characters in the stream. Returns
   108      * Skips the specified number of characters in the stream. Returns
   109      * the number of characters that were skipped.
   109      * the number of characters that were skipped.
   110      *
   110      *
   111      * <p>The <code>ns</code> parameter may be negative, even though the
   111      * <p>The {@code ns} parameter may be negative, even though the
   112      * <code>skip</code> method of the {@link Reader} superclass throws
   112      * {@code skip} method of the {@link Reader} superclass throws
   113      * an exception in this case. Negative values of <code>ns</code> cause the
   113      * an exception in this case. Negative values of {@code ns} cause the
   114      * stream to skip backwards. Negative return values indicate a skip
   114      * stream to skip backwards. Negative return values indicate a skip
   115      * backwards. It is not possible to skip backwards past the beginning of
   115      * backwards. It is not possible to skip backwards past the beginning of
   116      * the string.
   116      * the string.
   117      *
   117      *
   118      * <p>If the entire string has been read or skipped, then this method has
   118      * <p>If the entire string has been read or skipped, then this method has
   119      * no effect and always returns 0.
   119      * no effect and always returns 0.
   120      *
   120      *
   121      * @exception  IOException  If an I/O error occurs
   121      * @throws     IOException  If an I/O error occurs
   122      */
   122      */
   123     public long skip(long ns) throws IOException {
   123     public long skip(long ns) throws IOException {
   124         synchronized (lock) {
   124         synchronized (lock) {
   125             ensureOpen();
   125             ensureOpen();
   126             if (next >= length)
   126             if (next >= length)
   136     /**
   136     /**
   137      * Tells whether this stream is ready to be read.
   137      * Tells whether this stream is ready to be read.
   138      *
   138      *
   139      * @return True if the next read() is guaranteed not to block for input
   139      * @return True if the next read() is guaranteed not to block for input
   140      *
   140      *
   141      * @exception  IOException  If the stream is closed
   141      * @throws     IOException  If the stream is closed
   142      */
   142      */
   143     public boolean ready() throws IOException {
   143     public boolean ready() throws IOException {
   144         synchronized (lock) {
   144         synchronized (lock) {
   145             ensureOpen();
   145             ensureOpen();
   146             return true;
   146             return true;
   162      *                         read while still preserving the mark.  Because
   162      *                         read while still preserving the mark.  Because
   163      *                         the stream's input comes from a string, there
   163      *                         the stream's input comes from a string, there
   164      *                         is no actual limit, so this argument must not
   164      *                         is no actual limit, so this argument must not
   165      *                         be negative, but is otherwise ignored.
   165      *                         be negative, but is otherwise ignored.
   166      *
   166      *
   167      * @exception  IllegalArgumentException  If {@code readAheadLimit < 0}
   167      * @throws     IllegalArgumentException  If {@code readAheadLimit < 0}
   168      * @exception  IOException  If an I/O error occurs
   168      * @throws     IOException  If an I/O error occurs
   169      */
   169      */
   170     public void mark(int readAheadLimit) throws IOException {
   170     public void mark(int readAheadLimit) throws IOException {
   171         if (readAheadLimit < 0){
   171         if (readAheadLimit < 0){
   172             throw new IllegalArgumentException("Read-ahead limit < 0");
   172             throw new IllegalArgumentException("Read-ahead limit < 0");
   173         }
   173         }
   179 
   179 
   180     /**
   180     /**
   181      * Resets the stream to the most recent mark, or to the beginning of the
   181      * Resets the stream to the most recent mark, or to the beginning of the
   182      * string if it has never been marked.
   182      * string if it has never been marked.
   183      *
   183      *
   184      * @exception  IOException  If an I/O error occurs
   184      * @throws     IOException  If an I/O error occurs
   185      */
   185      */
   186     public void reset() throws IOException {
   186     public void reset() throws IOException {
   187         synchronized (lock) {
   187         synchronized (lock) {
   188             ensureOpen();
   188             ensureOpen();
   189             next = mark;
   189             next = mark;