public class BoundedInputStream
extends java.io.InputStream
This is useful to wrap ServletInputStreams. The ServletInputStream will block if you try to read content from it that isn't there, because it doesn't know whether the content hasn't arrived yet or whether the content has finished. So, one of these, initialized with the Content-length sent in the ServletInputStream's header, will stop it blocking, providing it's been sent with a correct content length.
(这是一个只提供一定长度的字节的流——如果它的位置超过这个长度,它将停止。这对于包装 ServletInputStreams 很有用。如果您尝试从中读取不存在的内容,则 ServletInputStream 将阻塞,因为它不知道内容是否尚未到达或内容是否已完成。因此,其中之一,使用 ServletInputStream 标头中发送的 Content-length 进行初始化,将阻止它阻塞,前提是它已以正确的内容长度发送。)Constructor and Description |
---|
BoundedInputStream(java.io.InputStream in)
Creates a new
BoundedInputStream that wraps the given input stream and is unlimited.
|
BoundedInputStream(java.io.InputStream in, long size)
Creates a new
BoundedInputStream that wraps the given input stream and limits it to a certain size.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close()
Invokes the delegate's
close() method if
isPropagateClose() is
true .
(如果 isPropagateClose() 为真,则调用委托的 close() 方法。)
|
boolean |
isPropagateClose()
Indicates whether the
close() method should propagate to the underling
InputStream .
(指示 close() 方法是否应该传播到底层 InputStream。)
|
void |
mark(int readlimit)
Invokes the delegate's
mark(int) method.
(调用委托的 mark(int) 方法。)
|
boolean |
markSupported()
Invokes the delegate's
markSupported() method.
(调用委托的 markSupported() 方法。)
|
int |
read()
Invokes the delegate's
read() method if the current position is less than the limit.
(如果当前位置小于限制,则调用委托的 read() 方法。)
|
int |
read(byte[] b)
Invokes the delegate's
read(byte[]) method.
(调用委托的 read(byte[]) 方法。)
|
int |
read(byte[] b, int off, int len)
Invokes the delegate's
read(byte[], int, int) method.
(调用委托的 read(byte[], int, int) 方法。)
|
void |
reset()
Invokes the delegate's
reset() method.
(调用委托的 reset() 方法。)
|
void |
setPropagateClose(boolean propagateClose)
Set whether the
close() method should propagate to the underling
InputStream .
(设置 close() 方法是否应该传播到底层 InputStream。)
|
long |
skip(long n)
Invokes the delegate's
skip(long) method.
(调用委托的 skip(long) 方法。)
|
java.lang.String |
toString()
Invokes the delegate's
toString() method.
(调用委托的 toString() 方法。)
|
public BoundedInputStream(java.io.InputStream in, long size)
BoundedInputStream
that wraps the given input stream and limits it to a certain size.
(创建一个新的 BoundedInputStream 包装给定的输入流并将其限制为特定大小。)
in
- The wrapped input stream
(in - 包装的输入流)
size
- The maximum number of bytes to return
(size - 要返回的最大字节数)
public BoundedInputStream(java.io.InputStream in)
BoundedInputStream
that wraps the given input stream and is unlimited.
(创建一个新的 BoundedInputStream 包装给定的输入流并且是无限的。)
in
- The wrapped input stream
(in - 包装的输入流)
public int read() throws java.io.IOException
read()
method if the current position is less than the limit.
(如果当前位置小于限制,则调用委托的 read() 方法。)
read
in class
java.io.InputStream
(读入类 java.io.InputStream)
java.io.IOException
- if an I/O error occurs
(java.io.IOException - 如果发生 I/O 错误)
public int read(byte[] b) throws java.io.IOException
read(byte[])
method.
(调用委托的 read(byte[]) 方法。)
read
in class
java.io.InputStream
b
- the buffer to read the bytes into
(b - 将字节读入的缓冲区)
java.io.IOException
- if an I/O error occurs
(java.io.IOException - 如果发生 I/O 错误)
public int read(byte[] b, int off, int len) throws java.io.IOException
read(byte[], int, int)
method.
(调用委托的 read(byte[], int, int) 方法。)
read
in class
java.io.InputStream
b
- the buffer to read the bytes into
(b - 将字节读入的缓冲区)
off
- The start offset
(off - 起始偏移量)
len
- The number of bytes to read
(len - 要读取的字节数)
java.io.IOException
- if an I/O error occurs
(java.io.IOException - 如果发生 I/O 错误)
public long skip(long n) throws java.io.IOException
skip(long)
method.
(调用委托的 skip(long) 方法。)
skip
in class
java.io.InputStream
n
- the number of bytes to skip
(n - 要跳过的字节数)
java.io.IOException
- if an I/O error occurs
(java.io.IOException - 如果发生 I/O 错误)
public int available() throws java.io.IOException
available
in class
java.io.InputStream
java.io.IOException
(java.io.IOException)
public java.lang.String toString()
toString()
method.
(调用委托的 toString() 方法。)
toString
in class
java.lang.Object
toString()
(委托的 toString())
public void close() throws java.io.IOException
close()
method if
isPropagateClose()
is
true
.
(如果 isPropagateClose() 为真,则调用委托的 close() 方法。)
close
in interface
java.io.Closeable
(在接口 java.io.Closeable 中关闭)
close
in interface
java.lang.AutoCloseable
(在接口 java.lang.AutoCloseable 中关闭)
close
in class
java.io.InputStream
java.io.IOException
- if an I/O error occurs
(java.io.IOException - 如果发生 I/O 错误)
public void reset() throws java.io.IOException
reset()
method.
(调用委托的 reset() 方法。)
reset
in class
java.io.InputStream
java.io.IOException
- if an I/O error occurs
(java.io.IOException - 如果发生 I/O 错误)
public void mark(int readlimit)
mark(int)
method.
(调用委托的 mark(int) 方法。)
mark
in class
java.io.InputStream
readlimit
- read ahead limit
(readlimit - 预读限制)
public boolean markSupported()
markSupported()
method.
(调用委托的 markSupported() 方法。)
markSupported
in class
java.io.InputStream
public boolean isPropagateClose()
close()
method should propagate to the underling
InputStream
.
(指示 close() 方法是否应该传播到底层 InputStream。)
true
if calling
close()
propagates to the
close()
method of the underlying stream or
false
if it does not.
(如果调用 close() 传播到底层流的 close() 方法,则为 true,否则为 false。)
public void setPropagateClose(boolean propagateClose)
close()
method should propagate to the underling
InputStream
.
(设置 close() 方法是否应该传播到底层 InputStream。)
propagateClose
-
true
if calling
close()
propagates to the
close()
method of the underlying stream or
false
if it does not.
(传播关闭 - 如果调用 close() 传播到底层流的 close() 方法,则为 true,否则为 false。)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.