equal
deleted
inserted
replaced
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 |
93 } |
93 } |
94 |
94 |
95 /** |
95 /** |
96 * Reads a single character. |
96 * Reads a single character. |
97 * |
97 * |
98 * @exception IOException If an I/O error occurs |
98 * @throws IOException If an I/O error occurs |
99 */ |
99 */ |
100 public int read() throws IOException { |
100 public int read() throws IOException { |
101 synchronized (lock) { |
101 synchronized (lock) { |
102 ensureOpen(); |
102 ensureOpen(); |
103 if (pos >= count) |
103 if (pos >= count) |
107 } |
107 } |
108 } |
108 } |
109 |
109 |
110 /** |
110 /** |
111 * Reads characters into a portion of an array. |
111 * Reads characters into a portion of an array. |
112 * @param b Destination buffer |
112 * @param b Destination buffer |
113 * @param off Offset at which to start storing characters |
113 * @param off Offset at which to start storing characters |
114 * @param len Maximum number of characters to read |
114 * @param len Maximum number of characters to read |
115 * @return The actual number of characters read, or -1 if |
115 * @return The actual number of characters read, or -1 if |
116 * the end of the stream has been reached |
116 * the end of the stream has been reached |
117 * |
117 * |
118 * @exception IOException If an I/O error occurs |
118 * @throws IOException If an I/O error occurs |
119 * @exception IndexOutOfBoundsException {@inheritDoc} |
119 * @throws IndexOutOfBoundsException {@inheritDoc} |
120 */ |
120 */ |
121 public int read(char b[], int off, int len) throws IOException { |
121 public int read(char b[], int off, int len) throws IOException { |
122 synchronized (lock) { |
122 synchronized (lock) { |
123 ensureOpen(); |
123 ensureOpen(); |
124 if ((off < 0) || (off > b.length) || (len < 0) || |
124 if ((off < 0) || (off > b.length) || (len < 0) || |
146 } |
146 } |
147 |
147 |
148 /** |
148 /** |
149 * Skips characters. Returns the number of characters that were skipped. |
149 * Skips characters. Returns the number of characters that were skipped. |
150 * |
150 * |
151 * <p>The <code>n</code> parameter may be negative, even though the |
151 * <p>The {@code n} parameter may be negative, even though the |
152 * <code>skip</code> method of the {@link Reader} superclass throws |
152 * {@code skip} method of the {@link Reader} superclass throws |
153 * an exception in this case. If <code>n</code> is negative, then |
153 * an exception in this case. If {@code n} is negative, then |
154 * this method does nothing and returns <code>0</code>. |
154 * this method does nothing and returns {@code 0}. |
155 * |
155 * |
156 * @param n The number of characters to skip |
156 * @param n The number of characters to skip |
157 * @return The number of characters actually skipped |
157 * @return The number of characters actually skipped |
158 * @exception IOException If the stream is closed, or an I/O error occurs |
158 * @throws IOException If the stream is closed, or an I/O error occurs |
159 */ |
159 */ |
160 public long skip(long n) throws IOException { |
160 public long skip(long n) throws IOException { |
161 synchronized (lock) { |
161 synchronized (lock) { |
162 ensureOpen(); |
162 ensureOpen(); |
163 |
163 |
175 |
175 |
176 /** |
176 /** |
177 * Tells whether this stream is ready to be read. Character-array readers |
177 * Tells whether this stream is ready to be read. Character-array readers |
178 * are always ready to be read. |
178 * are always ready to be read. |
179 * |
179 * |
180 * @exception IOException If an I/O error occurs |
180 * @throws IOException If an I/O error occurs |
181 */ |
181 */ |
182 public boolean ready() throws IOException { |
182 public boolean ready() throws IOException { |
183 synchronized (lock) { |
183 synchronized (lock) { |
184 ensureOpen(); |
184 ensureOpen(); |
185 return (count - pos) > 0; |
185 return (count - pos) > 0; |
201 * read while still preserving the mark. Because |
201 * read while still preserving the mark. Because |
202 * the stream's input comes from a character array, |
202 * the stream's input comes from a character array, |
203 * there is no actual limit; hence this argument is |
203 * there is no actual limit; hence this argument is |
204 * ignored. |
204 * ignored. |
205 * |
205 * |
206 * @exception IOException If an I/O error occurs |
206 * @throws IOException If an I/O error occurs |
207 */ |
207 */ |
208 public void mark(int readAheadLimit) throws IOException { |
208 public void mark(int readAheadLimit) throws IOException { |
209 synchronized (lock) { |
209 synchronized (lock) { |
210 ensureOpen(); |
210 ensureOpen(); |
211 markedPos = pos; |
211 markedPos = pos; |
214 |
214 |
215 /** |
215 /** |
216 * Resets the stream to the most recent mark, or to the beginning if it has |
216 * Resets the stream to the most recent mark, or to the beginning if it has |
217 * never been marked. |
217 * never been marked. |
218 * |
218 * |
219 * @exception IOException If an I/O error occurs |
219 * @throws IOException If an I/O error occurs |
220 */ |
220 */ |
221 public void reset() throws IOException { |
221 public void reset() throws IOException { |
222 synchronized (lock) { |
222 synchronized (lock) { |
223 ensureOpen(); |
223 ensureOpen(); |
224 pos = markedPos; |
224 pos = markedPos; |