author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58288 | 48e480e56aad |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55730
94f8a0b34117
8073213: javadoc of PushbackInputStream methods should specify NullPointerExceptions
bpb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.io; |
|
27 |
||
28 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
29 |
* A {@code PushbackInputStream} adds |
2 | 30 |
* functionality to another input stream, namely |
28867
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
31 |
* the ability to "push back" or "unread" bytes, |
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
32 |
* by storing pushed-back bytes in an internal buffer. |
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
33 |
* This is useful in situations where |
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
34 |
* it is convenient for a fragment of code |
2 | 35 |
* to read an indefinite number of data bytes |
36 |
* that are delimited by a particular byte |
|
37 |
* value; after reading the terminating byte, |
|
38 |
* the code fragment can "unread" it, so that |
|
39 |
* the next read operation on the input stream |
|
40 |
* will reread the byte that was pushed back. |
|
41 |
* For example, bytes representing the characters |
|
42 |
* constituting an identifier might be terminated |
|
43 |
* by a byte representing an operator character; |
|
44 |
* a method whose job is to read just an identifier |
|
45 |
* can read until it sees the operator and |
|
46 |
* then push the operator back to be re-read. |
|
47 |
* |
|
48 |
* @author David Connelly |
|
49 |
* @author Jonathan Payne |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
50 |
* @since 1.0 |
2 | 51 |
*/ |
52 |
public |
|
53 |
class PushbackInputStream extends FilterInputStream { |
|
54 |
/** |
|
55 |
* The pushback buffer. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
56 |
* @since 1.1 |
2 | 57 |
*/ |
58 |
protected byte[] buf; |
|
59 |
||
60 |
/** |
|
61 |
* The position within the pushback buffer from which the next byte will |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
62 |
* be read. When the buffer is empty, {@code pos} is equal to |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
63 |
* {@code buf.length}; when the buffer is full, {@code pos} is |
2 | 64 |
* equal to zero. |
65 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
66 |
* @since 1.1 |
2 | 67 |
*/ |
68 |
protected int pos; |
|
69 |
||
70 |
/** |
|
71 |
* Check to make sure that this stream has not been closed |
|
72 |
*/ |
|
73 |
private void ensureOpen() throws IOException { |
|
74 |
if (in == null) |
|
75 |
throw new IOException("Stream closed"); |
|
76 |
} |
|
77 |
||
78 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
79 |
* Creates a {@code PushbackInputStream} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
80 |
* with a pushback buffer of the specified {@code size}, |
28867
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
81 |
* and saves its argument, the input stream |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
82 |
* {@code in}, for later use. Initially, |
28867
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
83 |
* the pushback buffer is empty. |
2 | 84 |
* |
85 |
* @param in the input stream from which bytes will be read. |
|
86 |
* @param size the size of the pushback buffer. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
87 |
* @throws IllegalArgumentException if {@code size <= 0} |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
88 |
* @since 1.1 |
2 | 89 |
*/ |
90 |
public PushbackInputStream(InputStream in, int size) { |
|
91 |
super(in); |
|
92 |
if (size <= 0) { |
|
93 |
throw new IllegalArgumentException("size <= 0"); |
|
94 |
} |
|
95 |
this.buf = new byte[size]; |
|
96 |
this.pos = size; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
100 |
* Creates a {@code PushbackInputStream} |
28867
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
101 |
* with a 1-byte pushback buffer, and saves its argument, the input stream |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
102 |
* {@code in}, for later use. Initially, |
28867
470553603264
8064562: (doc) errors in java.io.PushbackInputStream API documentation
bpb
parents:
25859
diff
changeset
|
103 |
* the pushback buffer is empty. |
2 | 104 |
* |
105 |
* @param in the input stream from which bytes will be read. |
|
106 |
*/ |
|
107 |
public PushbackInputStream(InputStream in) { |
|
108 |
this(in, 1); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Reads the next byte of data from this input stream. The value |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
113 |
* byte is returned as an {@code int} in the range |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
114 |
* {@code 0} to {@code 255}. If no byte is available |
2 | 115 |
* because the end of the stream has been reached, the value |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
116 |
* {@code -1} is returned. This method blocks until input data |
2 | 117 |
* is available, the end of the stream is detected, or an exception |
118 |
* is thrown. |
|
119 |
* |
|
120 |
* <p> This method returns the most recently pushed-back byte, if there is |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
121 |
* one, and otherwise calls the {@code read} method of its underlying |
2 | 122 |
* input stream and returns whatever value that method returns. |
123 |
* |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
124 |
* @return the next byte of data, or {@code -1} if the end of the |
2 | 125 |
* stream has been reached. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
126 |
* @throws IOException if this input stream has been closed by |
2 | 127 |
* invoking its {@link #close()} method, |
128 |
* or an I/O error occurs. |
|
129 |
* @see java.io.InputStream#read() |
|
130 |
*/ |
|
131 |
public int read() throws IOException { |
|
132 |
ensureOpen(); |
|
133 |
if (pos < buf.length) { |
|
134 |
return buf[pos++] & 0xff; |
|
135 |
} |
|
136 |
return super.read(); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
140 |
* Reads up to {@code len} bytes of data from this input stream into |
2 | 141 |
* an array of bytes. This method first reads any pushed-back bytes; after |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
142 |
* that, if fewer than {@code len} bytes have been read then it |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
143 |
* reads from the underlying input stream. If {@code len} is not zero, the method |
2 | 144 |
* blocks until at least 1 byte of input is available; otherwise, no |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
145 |
* bytes are read and {@code 0} is returned. |
2 | 146 |
* |
147 |
* @param b the buffer into which the data is read. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
148 |
* @param off the start offset in the destination array {@code b} |
2 | 149 |
* @param len the maximum number of bytes read. |
150 |
* @return the total number of bytes read into the buffer, or |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
151 |
* {@code -1} if there is no more data because the end of |
2 | 152 |
* the stream has been reached. |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
153 |
* @throws NullPointerException If {@code b} is {@code null}. |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
154 |
* @throws IndexOutOfBoundsException If {@code off} is negative, |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
155 |
* {@code len} is negative, or {@code len} is greater than |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
156 |
* {@code b.length - off} |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
157 |
* @throws IOException if this input stream has been closed by |
2 | 158 |
* invoking its {@link #close()} method, |
159 |
* or an I/O error occurs. |
|
160 |
* @see java.io.InputStream#read(byte[], int, int) |
|
161 |
*/ |
|
162 |
public int read(byte[] b, int off, int len) throws IOException { |
|
163 |
ensureOpen(); |
|
164 |
if (b == null) { |
|
165 |
throw new NullPointerException(); |
|
166 |
} else if (off < 0 || len < 0 || len > b.length - off) { |
|
167 |
throw new IndexOutOfBoundsException(); |
|
168 |
} else if (len == 0) { |
|
169 |
return 0; |
|
170 |
} |
|
171 |
||
172 |
int avail = buf.length - pos; |
|
173 |
if (avail > 0) { |
|
174 |
if (len < avail) { |
|
175 |
avail = len; |
|
176 |
} |
|
177 |
System.arraycopy(buf, pos, b, off, avail); |
|
178 |
pos += avail; |
|
179 |
off += avail; |
|
180 |
len -= avail; |
|
181 |
} |
|
182 |
if (len > 0) { |
|
183 |
len = super.read(b, off, len); |
|
184 |
if (len == -1) { |
|
185 |
return avail == 0 ? -1 : avail; |
|
186 |
} |
|
187 |
return avail + len; |
|
188 |
} |
|
189 |
return avail; |
|
190 |
} |
|
191 |
||
192 |
/** |
|
193 |
* Pushes back a byte by copying it to the front of the pushback buffer. |
|
194 |
* After this method returns, the next byte to be read will have the value |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
195 |
* {@code (byte)b}. |
2 | 196 |
* |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
197 |
* @param b the {@code int} value whose low-order |
2 | 198 |
* byte is to be pushed back. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
199 |
* @throws IOException If there is not enough room in the pushback |
2 | 200 |
* buffer for the byte, or this input stream has been closed by |
201 |
* invoking its {@link #close()} method. |
|
202 |
*/ |
|
203 |
public void unread(int b) throws IOException { |
|
204 |
ensureOpen(); |
|
205 |
if (pos == 0) { |
|
206 |
throw new IOException("Push back buffer is full"); |
|
207 |
} |
|
208 |
buf[--pos] = (byte)b; |
|
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Pushes back a portion of an array of bytes by copying it to the front |
|
213 |
* of the pushback buffer. After this method returns, the next byte to be |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
214 |
* read will have the value {@code b[off]}, the byte after that will |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
215 |
* have the value {@code b[off+1]}, and so forth. |
2 | 216 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
217 |
* @param b the byte array to push back. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
218 |
* @param off the start offset of the data. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
219 |
* @param len the number of bytes to push back. |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
220 |
* @throws NullPointerException If {@code b} is {@code null}. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
221 |
* @throws IOException If there is not enough room in the pushback |
2 | 222 |
* buffer for the specified number of bytes, |
223 |
* or this input stream has been closed by |
|
224 |
* invoking its {@link #close()} method. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
225 |
* @since 1.1 |
2 | 226 |
*/ |
227 |
public void unread(byte[] b, int off, int len) throws IOException { |
|
228 |
ensureOpen(); |
|
229 |
if (len > pos) { |
|
230 |
throw new IOException("Push back buffer is full"); |
|
231 |
} |
|
232 |
pos -= len; |
|
233 |
System.arraycopy(b, off, buf, pos, len); |
|
234 |
} |
|
235 |
||
236 |
/** |
|
237 |
* Pushes back an array of bytes by copying it to the front of the |
|
238 |
* pushback buffer. After this method returns, the next byte to be read |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
239 |
* will have the value {@code b[0]}, the byte after that will have the |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
240 |
* value {@code b[1]}, and so forth. |
2 | 241 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
242 |
* @param b the byte array to push back |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
243 |
* @throws NullPointerException If {@code b} is {@code null}. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
244 |
* @throws IOException If there is not enough room in the pushback |
2 | 245 |
* buffer for the specified number of bytes, |
246 |
* or this input stream has been closed by |
|
247 |
* invoking its {@link #close()} method. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
248 |
* @since 1.1 |
2 | 249 |
*/ |
250 |
public void unread(byte[] b) throws IOException { |
|
251 |
unread(b, 0, b.length); |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* Returns an estimate of the number of bytes that can be read (or |
|
256 |
* skipped over) from this input stream without blocking by the next |
|
257 |
* invocation of a method for this input stream. The next invocation might be |
|
258 |
* the same thread or another thread. A single read or skip of this |
|
259 |
* many bytes will not block, but may read or skip fewer bytes. |
|
260 |
* |
|
261 |
* <p> The method returns the sum of the number of bytes that have been |
|
262 |
* pushed back and the value returned by {@link |
|
263 |
* java.io.FilterInputStream#available available}. |
|
264 |
* |
|
265 |
* @return the number of bytes that can be read (or skipped over) from |
|
266 |
* the input stream without blocking. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
267 |
* @throws IOException if this input stream has been closed by |
2 | 268 |
* invoking its {@link #close()} method, |
269 |
* or an I/O error occurs. |
|
270 |
* @see java.io.FilterInputStream#in |
|
271 |
* @see java.io.InputStream#available() |
|
272 |
*/ |
|
273 |
public int available() throws IOException { |
|
274 |
ensureOpen(); |
|
7280
81f10887bf74
6631046: BufferedInputStream.available() reports negative int on very large inputstream
mchung
parents:
5506
diff
changeset
|
275 |
int n = buf.length - pos; |
81f10887bf74
6631046: BufferedInputStream.available() reports negative int on very large inputstream
mchung
parents:
5506
diff
changeset
|
276 |
int avail = super.available(); |
81f10887bf74
6631046: BufferedInputStream.available() reports negative int on very large inputstream
mchung
parents:
5506
diff
changeset
|
277 |
return n > (Integer.MAX_VALUE - avail) |
81f10887bf74
6631046: BufferedInputStream.available() reports negative int on very large inputstream
mchung
parents:
5506
diff
changeset
|
278 |
? Integer.MAX_VALUE |
81f10887bf74
6631046: BufferedInputStream.available() reports negative int on very large inputstream
mchung
parents:
5506
diff
changeset
|
279 |
: n + avail; |
2 | 280 |
} |
281 |
||
282 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
283 |
* Skips over and discards {@code n} bytes of data from this |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
284 |
* input stream. The {@code skip} method may, for a variety of |
2 | 285 |
* reasons, end up skipping over some smaller number of bytes, |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
286 |
* possibly zero. If {@code n} is negative, no bytes are skipped. |
2 | 287 |
* |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
288 |
* <p> The {@code skip} method of {@code PushbackInputStream} |
2 | 289 |
* first skips over the bytes in the pushback buffer, if any. It then |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
290 |
* calls the {@code skip} method of the underlying input stream if |
2 | 291 |
* more bytes need to be skipped. The actual number of bytes skipped |
292 |
* is returned. |
|
293 |
* |
|
294 |
* @param n {@inheritDoc} |
|
295 |
* @return {@inheritDoc} |
|
39121
a1a92fce338a
8136738: InputStream documentation for IOException in skip() is unclear or incorrect
bpb
parents:
28867
diff
changeset
|
296 |
* @throws IOException if the stream has been closed by |
a1a92fce338a
8136738: InputStream documentation for IOException in skip() is unclear or incorrect
bpb
parents:
28867
diff
changeset
|
297 |
* invoking its {@link #close()} method, |
a1a92fce338a
8136738: InputStream documentation for IOException in skip() is unclear or incorrect
bpb
parents:
28867
diff
changeset
|
298 |
* {@code in.skip(n)} throws an IOException, |
a1a92fce338a
8136738: InputStream documentation for IOException in skip() is unclear or incorrect
bpb
parents:
28867
diff
changeset
|
299 |
* or an I/O error occurs. |
2 | 300 |
* @see java.io.FilterInputStream#in |
301 |
* @see java.io.InputStream#skip(long n) |
|
302 |
* @since 1.2 |
|
303 |
*/ |
|
304 |
public long skip(long n) throws IOException { |
|
305 |
ensureOpen(); |
|
306 |
if (n <= 0) { |
|
307 |
return 0; |
|
308 |
} |
|
309 |
||
310 |
long pskip = buf.length - pos; |
|
311 |
if (pskip > 0) { |
|
312 |
if (n < pskip) { |
|
313 |
pskip = n; |
|
314 |
} |
|
315 |
pos += pskip; |
|
316 |
n -= pskip; |
|
317 |
} |
|
318 |
if (n > 0) { |
|
319 |
pskip += super.skip(n); |
|
320 |
} |
|
321 |
return pskip; |
|
322 |
} |
|
323 |
||
324 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
325 |
* Tests if this input stream supports the {@code mark} and |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
326 |
* {@code reset} methods, which it does not. |
2 | 327 |
* |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
328 |
* @return {@code false}, since this class does not support the |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
329 |
* {@code mark} and {@code reset} methods. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
330 |
* @see java.io.InputStream#mark(int) |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
331 |
* @see java.io.InputStream#reset() |
2 | 332 |
*/ |
333 |
public boolean markSupported() { |
|
334 |
return false; |
|
335 |
} |
|
336 |
||
337 |
/** |
|
338 |
* Marks the current position in this input stream. |
|
339 |
* |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
340 |
* <p> The {@code mark} method of {@code PushbackInputStream} |
2 | 341 |
* does nothing. |
342 |
* |
|
343 |
* @param readlimit the maximum limit of bytes that can be read before |
|
344 |
* the mark position becomes invalid. |
|
345 |
* @see java.io.InputStream#reset() |
|
346 |
*/ |
|
347 |
public synchronized void mark(int readlimit) { |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* Repositions this stream to the position at the time the |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
352 |
* {@code mark} method was last called on this input stream. |
2 | 353 |
* |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
354 |
* <p> The method {@code reset} for class |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
355 |
* {@code PushbackInputStream} does nothing except throw an |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
356 |
* {@code IOException}. |
2 | 357 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
358 |
* @throws IOException if this method is invoked. |
2 | 359 |
* @see java.io.InputStream#mark(int) |
360 |
* @see java.io.IOException |
|
361 |
*/ |
|
362 |
public synchronized void reset() throws IOException { |
|
363 |
throw new IOException("mark/reset not supported"); |
|
364 |
} |
|
365 |
||
366 |
/** |
|
367 |
* Closes this input stream and releases any system resources |
|
368 |
* associated with the stream. |
|
369 |
* Once the stream has been closed, further read(), unread(), |
|
370 |
* available(), reset(), or skip() invocations will throw an IOException. |
|
371 |
* Closing a previously closed stream has no effect. |
|
372 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55730
diff
changeset
|
373 |
* @throws IOException if an I/O error occurs. |
2 | 374 |
*/ |
375 |
public synchronized void close() throws IOException { |
|
8540
ed028ce13912
7021327: Changes for 7020888 included changes to other files in error
alanb
parents:
8539
diff
changeset
|
376 |
if (in == null) |
ed028ce13912
7021327: Changes for 7020888 included changes to other files in error
alanb
parents:
8539
diff
changeset
|
377 |
return; |
ed028ce13912
7021327: Changes for 7020888 included changes to other files in error
alanb
parents:
8539
diff
changeset
|
378 |
in.close(); |
ed028ce13912
7021327: Changes for 7020888 included changes to other files in error
alanb
parents:
8539
diff
changeset
|
379 |
in = null; |
ed028ce13912
7021327: Changes for 7020888 included changes to other files in error
alanb
parents:
8539
diff
changeset
|
380 |
buf = null; |
2 | 381 |
} |
382 |
} |