java.io.ByteArrayInputStream翻译

 
JavaTM 2 Platform
Std. Ed. v1.4.2

java.io
Class ByteArrayInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.ByteArrayInputStream

public class ByteArrayInputStream extends InputStream

A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream. An internal counter keeps track of the next byte to be supplied by the read method. ByteArrayInputStream包含一个内部缓冲,存储从流中读取的字节。 一个内部计数器用于跟踪read方法提供的下一个字节。

Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException. 关闭ByteArrayInputStream无效。本类的该方法可以在关闭流后调用,而不生成IOException。

Since:
JDK1.0
See Also:
StringBufferInputStream

Field Summary
protected  byte[]buf
          An array of bytes that was provided by the creator of the stream. 由该流的创建者提供的字节数组。
protected  intcount
          The index one greater than the last valid character in the input stream buffer. 等于流缓冲的最后一个有效字符的下标+1。
protected  intmark
          The currently marked position in the stream. 流的当前标记位置。
protected  intpos
          The index of the next character to read from the input stream buffer. 要从输入流缓冲读取的下一个字符的下标。
 
Constructor Summary
ByteArrayInputStream(byte[] buf)
          Creates a ByteArrayInputStream so that it uses buf as its buffer array. 创建一个ByteArrayInputStream,使用buf作为它的缓冲数组。
ByteArrayInputStream(byte[] buf, int offset, int length)
          Creates ByteArrayInputStream that uses buf as its buffer array. 创建ByteArrayInputStream,使用buf作为它的缓冲数组。
 
Method Summary
 intavailable()
          Returns the number of bytes that can be read from this input stream without blocking. 返回可以从输入流不阻塞读取的字节数。
 voidclose()
          Closing a ByteArrayInputStream has no effect. 关闭ByteArrayInputStream无效。
 voidmark(int readAheadLimit)
          Set the current marked position in the stream. 设置流的当前标记位置。
 booleanmarkSupported()
          Tests if this InputStream supports mark/reset. 测试此InputStream是否支持标记/重置。
 intread()
          Reads the next byte of data from this input stream. 读取输入流的下一个字节。
 intread(byte[] b, int off, int len)
          Reads up to len bytes of data into an array of bytes from this input stream. 从输入流中将最多len个字节读入字节数组。
 voidreset()
          Resets the buffer to the marked position. 将缓冲重置为标记位。
 longskip(long n)
          Skips n bytes of input from this input stream. 跳过输入流的n个输入字节。
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected byte[] buf
An array of bytes that was provided by the creator of the stream. Elements buf[0] through buf[count-1] are the only bytes that can ever be read from the stream; element buf[pos] is the next byte to be read. 由该流的创建者提供的字节数组。元素buf[0]到buf[count-1]是可以从流中读取的字节; 元素buf[pos]是要读取的下一个字节。

 


pos

protected int pos
The index of the next character to read from the input stream buffer. This value should always be nonnegative and not larger than the value of count. The next byte to be read from the input stream buffer will be buf[pos]. 要从输入流缓冲读取的下一个字符的下标。该值总是为非负数,不大于count值。 要读取输入流缓冲的下一个字节为buf[pos]。

 


mark

protected int mark
The currently marked position in the stream. ByteArrayInputStream objects are marked at position zero by default when constructed. They may be marked at another position within the buffer by the mark() method. The current buffer position is set to this point by the reset() method. 流的当前标记位置。构造时默认将ByteArrayInputStream对象标记在位置零处。 通过mark()方法可将其标记在缓冲内的另一位置。通过reset()方法将当前缓冲位置设置为此点。

If no mark has been set, then the value of mark is the offset passed to the constructor (or 0 if the offset was not supplied). 如果没有设置标记,那么标记值为传递给构造函数的偏移量(如果没有 提供偏移量则为0)。

Since:
JDK1.1

count

protected int count
The index one greater than the last valid character in the input stream buffer. This value should always be nonnegative and not larger than the length of buf. It is one greater than the position of the last byte within buf that can ever be read from the input stream buffer. 等于流缓冲的最后一个有效字符的下标+1。该值总是为非负数,不大于buf的长度。 它等于buf中最后一个可从输入流缓冲中读取的字节位置+1。

 

Constructor Detail

ByteArrayInputStream

public ByteArrayInputStream(byte[] buf)
Creates a ByteArrayInputStream so that it uses buf as its buffer array. The buffer array is not copied. The initial value of pos is 0 and the initial value of count is the length of buf. 创建一个ByteArrayInputStream,使用buf作为它的缓冲数组。该缓冲数组不是复制得到的。 pos的初始值是0,count的初始值为buf的长度。

 

Parameters:
buf - the input buffer.

ByteArrayInputStream

public ByteArrayInputStream(byte[] buf,
                            int offset,
                            int length)
Creates ByteArrayInputStream that uses buf as its buffer array. The initial value of pos is offset and the initial value of count is the minimum of offset+length and buf.length. The buffer array is not copied. The buffer's mark is set to the specified offset. 创建ByteArrayInputStream,使用buf作为它的缓冲数组。pos的初始值是offset, count的初始值是offset+length和buf.length中的较小值。该缓冲数组不是复制得到的。 缓冲的标记设置为指定的偏移量。

 

Parameters:
buf - the input buffer. 输入缓冲。
offset - the offset in the buffer of the first byte to read. 缓冲的偏移量,即要读取的第一个字节。
length - the maximum number of bytes to read from the buffer. 要从缓冲读取的字节最大数。
Method Detail

read

public int read()
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. 读取输入流的下一个字节。以int形式返回字节值,范围为0到255。 如果因为已到达流末尾而没有可用的字节,则返回值 -1。

This read method cannot block. 此read方法不会阻塞。

Specified by:
read in class InputStream
Returns:
the next byte of data, or -1 if the end of the stream has been reached. 数据的下一个字节,如果已到达流末尾返回-1。

read

public int read(byte[] b,
                int off,
                int len)
Reads up to len bytes of data into an array of bytes from this input stream. If pos equals count, then -1 is returned to indicate end of file. Otherwise, the number k of bytes read is equal to the smaller of len and count-pos. If k is positive, then bytes buf[pos] through buf[pos+k-1] are copied into b[off] through b[off+k-1] in the manner performed by System.arraycopy. The value k is added into pos and k is returned. 从输入流中将最多len个字节读入字节数组。如果pos等于count, 则返回-1表示文件结束。否则,读取的字节数k等于len和count-pos中的较小值。 如果k为正数,则以System.arraycopy执行的方式将buf[pos]到buf[pos+k-1]的 字节复制到b[off]到b[off+k-1]中。将值k与pos相加并返回k。

This read method cannot block. 此read方法不会阻塞。

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read. 数据读入的缓冲。
off - the start offset of the data. 数据的起始偏移量。
len - the maximum number of bytes read. 读取字节的最大量。
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached. 读入缓冲的字节总和,如果因为已到达流末尾而不再有数据,返回-1。
See Also:
InputStream.read()

skip

public long skip(long n)
Skips n bytes of input from this input stream. Fewer bytes might be skipped if the end of the input stream is reached. The actual number k of bytes to be skipped is equal to the smaller of n and count-pos. The value k is added into pos and k is returned. 跳过输入流的n个输入字节。如果已到达输入流末尾,则可能会跳过较少的字节。 实际跳过的字节数k等于n和count-pos中的较小值。将值k与pos相加并返回k。

 

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to be skipped. 要跳过的字节数。
Returns:
the actual number of bytes skipped. 跳过的实际字节数。

available

public int available()
Returns the number of bytes that can be read from this input stream without blocking. The value returned is count - pos, which is the number of bytes remaining to be read from the input buffer. 返回可以从输入流不阻塞读取的字节数。返回值为count - pos,它是从输入缓冲中读取的剩余字节数。

 

Overrides:
available in class InputStream
Returns:
the number of bytes that can be read from the input stream without blocking. 从输入流不阻塞读取的字节数。

markSupported

public boolean markSupported()
Tests if this InputStream supports mark/reset. The markSupported method of ByteArrayInputStream always returns true. 测试此InputStream是否支持标记/重置。ByteArrayInputStream的markSupported方法总是返回true。

 

Overrides:
markSupported in class InputStream
Returns:
true if this stream instance supports the mark and reset methods; false otherwise. 如果流实例支持mark和reset方法,返回true;否则为false。
Since:
JDK1.1
See Also:
InputStream.mark(int) , InputStream.reset()

mark

public void mark(int readAheadLimit)
Set the current marked position in the stream. ByteArrayInputStream objects are marked at position zero by default when constructed. They may be marked at another position within the buffer by this method. 设置流的当前标记位置。ByteArrayInputStream在构造时默认为比较位为0。 通过该方法也可以标记缓冲的另一个位置。

If no mark has been set, then the value of the mark is the offset passed to the constructor (or 0 if the offset was not supplied). 如果没有设置标记,那么标记值为传递给构造函数的偏移量(如果没有 提供偏移量则为0)。

Overrides:
mark in class InputStream
Parameters:
readAheadLimit - the maximum limit of bytes that can be read before the mark position becomes invalid. 在标记位失效之前可读取的最大字节数。
Since:
JDK1.1
See Also:
InputStream.reset()

reset

public void reset()
Resets the buffer to the marked position. The marked position is 0 unless another position was marked or an offset was specified in the constructor. 将缓冲重置为标记位。标记位为0,除非已标记了另一个位置或者在构造函数中指定了偏移量。

 

Overrides:
reset in class InputStream
See Also:
InputStream.mark(int) , IOException

close

public void close()
           throws IOException
Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException. 关闭ByteArrayInputStream无效。本类的该方法可以在关闭流后调用,而不生成IOException。

 

Overrides:
close in class InputStream
Throws:
IOException - if an I/O error occurs. 如果I/O错误发生时抛出。

JavaTM 2 Platform
Std. Ed. v1.4.2

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值