📄 javaio.doc8.html
字号:
<html>
<head>
<title>The Java Language Specification The Package java.io </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<a href="index.html">Contents</a> | <a href="javaio.doc7.html">Prev</a> | <a href="javaio.doc9.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="28120"></a>
<center><h1>22.10 The Class <code>java.io.BufferedInputStream</code></h1></center>
<a name="28121"></a>
A <code>BufferedInputStream</code> adds functionality to another input stream-namely,
the ability to buffer the input and to support the <code>mark</code> and <code>reset</code> methods. When
the <code>BufferedInputStream</code> is created, an internal buffer array is created. As bytes
from the stream are read or skipped, the internal buffer is refilled as necessary
from the contained input stream, many bytes at a time. The <code>mark</code> operation
remembers a point in the input stream and the <code>reset</code> operation causes all the
bytes read since the most recent <code>mark</code> operation to be reread before new bytes are
taken from the contained input stream.
<p><pre><a name="24309"></a>public class <code><b>BufferedInputStream</b></code> extends FilterInputStream {
<a name="9030"></a> protected byte[] <code><b>buf</b></code>;
<a name="9031"></a> protected int <code><b>count</b></code> = 0;
<a name="9032"></a> protected int <code><b>pos</b></code> = 0;
<a name="9033"></a> protected int <code><b>markpos</b></code> = -1;
<a name="9034"></a> protected int <code><b>marklimit</b></code> = 0;
<a name="9035"></a> public <code><b>BufferedInputStream</b></code>(InputStream in);
<a name="9036"></a> public <code><b>BufferedInputStream</b></code>(InputStream in, int size);
<a name="9037"></a> public int <code><b>read</b></code>() throws IOException;
<a name="24262"></a> public int <code><b>read</b></code>(byte[] b)
<a name="32344"></a> throws IOException, NullPointerException;
<a name="24267"></a> public int <code><b>read</b></code>(byte[] b, int off, int len)
<a name="24268"></a> throws IOException, NullPointerException,
<a name="32347"></a> IndexOutOfBoundsException;
<a name="9039"></a> public long <code><b>skip</b></code>(long n) throws IOException;
<a name="9040"></a> public int <code><b>available</b></code>() throws IOException;
<a name="9041"></a> public void <code><b>mark</b></code>(int readlimit);
<a name="9042"></a> public void <code><b>reset</b></code>() throws IOException;
<a name="9043"></a> public boolean <code><b>markSupported</b></code>();
<a name="9044"></a>}
</pre><a name="9045"></a>
<p><font size=+1><strong>22.10.1 </strong> <code>protected byte[] <code><b>buf</b></code>;</code></font>
<p>
<a name="24333"></a>
The internal buffer array. When necessary, it may be replaced by another array of
a different size.
<p><a name="9046"></a>
<p><font size=+1><strong>22.10.2 </strong> <code>protected int <code><b>count</b></code> = 0;</code></font>
<p>
<a name="24334"></a>
This value is always in the range <code>0</code> through <code>buf.length</code>; elements <code>buf[0]</code>
through <code>buf[count-1] </code>contain buffered input data obtained from the underlying
input stream.
<p><a name="9047"></a>
<p><font size=+1><strong>22.10.3 </strong> <code>protected int <code><b>pos</b></code> = 0;</code></font>
<p>
<a name="24339"></a>
This value is always in the range <code>0</code> through <code>count</code>. If it is less than <code>count</code>, then
<code>buf[pos]</code> is the next byte to be supplied as input; if it is equal to <code>count</code>, then the
next <code>read</code> or <code>skip</code> operation will require more bytes to be read from the contained
input stream.
<p><a name="9048"></a>
<p><font size=+1><strong>22.10.4 </strong> <code>protected int <code><b>markpos</b></code> = -1;</code></font>
<p>
<a name="24336"></a>
This value is always in the range <code>-1</code> through <code>pos</code>. If there is no marked position in
the input stream, this field is <code>-1</code>. If there is a marked position in the input stream,
then <code>buf[markpos]</code> is the first byte to be supplied as input after a <code>reset</code> operation.
If <code>markpos</code> is not <code>-1</code>, then all bytes from positions <code>buf[markpos]</code> through
<code>buf[pos-1]</code> must remain in the buffer array (though they may be moved to
another place in the buffer array, with suitable adjustments to the values of <code>count</code>,
<code>pos</code>, and <code>markpos</code>); they may not be discarded unless and until the difference
between <code>pos</code> and <code>markpos</code> exceeds <code>marklimit</code>.
<p><a name="9049"></a>
<p><font size=+1><strong>22.10.5 </strong> <code>protected int <code><b>marklimit</b></code>;</code></font>
<p>
<a name="24357"></a>
Whenever the difference between <code>pos</code> and <code>markpos</code> exceeds <code>marklimit</code>, then the
mark may be dropped by setting <code>markpos</code> to <code>-1</code>.
<p><a name="9050"></a>
<p><font size=+1><strong>22.10.6 </strong> <code>public <code><b>BufferedInputStream</b></code>(InputStream in)</code></font>
<p>
<a name="24360"></a>
This constructor initializes a newly created <code>BufferedInputStream</code> by saving its
argument, the input stream <code>in</code>, for later use. An internal buffer array is created and
stored in <code>buf</code>.
<p><a name="9051"></a>
<p><font size=+1><strong>22.10.7 </strong> <code>public <code><b>BufferedInputStream</b></code>(InputStream in, int size)</code></font>
<p>
<a name="24390"></a>
This constructor initializes a newly created <code>BufferedInputStream</code> by saving its
argument, the input stream <code>in</code>, for later use. An internal buffer array of length
<code>size</code> is created and stored in <code>buf</code>.
<p><a name="9052"></a>
<p><font size=+1><strong>22.10.8 </strong> <code>public int <code><b>read</b></code>() throws IOException</code></font>
<p>
<a name="24403"></a>
See the general contract of the <code>read</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28142">(§22.3.1)</a>.
<p><a name="24408"></a>
Overrides the <code>read</code> method of <code>FilterInputStream</code> <a href="javaio.doc7.html#28556">(§22.9.3)</a>.<p>
<a name="24296"></a>
<p><font size=+1><strong>22.10.9 </strong> <code>public int <code><b>read</b></code>(byte[] b)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="24425"></a>
See the general contract of the <code>read</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28150">(§22.3.2)</a>.
<p><a name="24430"></a>
Overrides the <code>read</code> method of <code>FilterInputStream</code> <a href="javaio.doc7.html#28563">(§22.9.4)</a>.<p>
<a name="32337"></a>
<p><font size=+1><strong>22.10.10 </strong> <code>public int <code><b>read</b></code>(byte[] b, int off, int len)<br>throws IOException, NullPointerException,      IndexOutOfBoundsException</code></font>
<p>
<a name="24453"></a>
See the general contract of the <code>read</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28164">(§22.3.3)</a>.
<p><a name="24458"></a>
Overrides the <code>read</code> method of <code>FilterInputStream</code> <a href="javaio.doc18.html#24613">(§22.9.5)</a>.<p>
<a name="9054"></a>
<p><font size=+1><strong>22.10.11 </strong> <code>public long <code><b>skip</b></code>(long n) throws IOException</code></font>
<p>
<a name="24467"></a>
See the general contract of the <code>skip</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28178">(§22.3.4)</a>.
<p><a name="24472"></a>
Overrides the <code>skip</code> method of <code>FilterInputStream</code> <a href="javaio.doc7.html#28577">(§22.9.6)</a>.<p>
<a name="9055"></a>
<p><font size=+1><strong>22.10.12 </strong> <code>public int <code><b>available</b></code>() throws IOException</code></font>
<p>
<a name="24506"></a>
See the general contract of the <code>available</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28182">(§22.3.5)</a>.
<p><a name="24520"></a>
Overrides the <code>available</code> method of <code>FilterInputStream</code> <a href="javaio.doc7.html#28584">(§22.9.7)</a>.<p>
<a name="9056"></a>
<p><font size=+1><strong>22.10.13 </strong> <code>public void <code><b>mark</b></code>(int readlimit)</code></font>
<p>
<a name="24500"></a>
The field <code>marklimit</code> is set equal to the argument and <code>markpos</code> is set equal to <code>pos
</code><p><a name="34366"></a>
Overrides the <code>mark</code> method of <code>FilterInputStream</code> <a href="javaio.doc7.html#28598">(§22.9.9)</a>.<p>
<a name="9057"></a>
<p><font size=+1><strong>22.10.14 </strong> <code>public void <code><b>reset</b></code>() throws IOException</code></font>
<p>
<a name="34387"></a>
See the general contract of the <code>reset</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28197">(§22.3.8)</a>.
<p><a name="34388"></a>
If <code>markpos</code> is <code>-1</code> (no mark has been set or the mark has been invalidated), an <code>IOException</code> is thrown. Otherwise, <code>pos</code> is set equal to <code>markpos</code>.<p>
<a name="24487"></a>
Overrides the <code>reset</code> method of <code>FilterInputStream</code> <a href="javaio.doc12.html#31849">(§22.9.10)</a>.<p>
<a name="9058"></a>
<p><font size=+1><strong>22.10.15 </strong> <code>public boolean <code><b>markSupported</b></code>()</code></font>
<p>
<a name="24501"></a>
This method returns <code>true</code> (a <code>BufferedInputStream</code> always supports <code>mark</code>).
<p><a name="34380"></a>
Overrides the <code>markSupported</code> method of <code>FilterInputStream</code> <a href="javaio.doc7.html#28611">(§22.9.11)</a>.<p>
<a name="34375"></a>
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javaio.doc7.html">Prev</a> | <a href="javaio.doc9.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -