public class CachedInputStream extends InputStream
| 限定符和类型 | 类和说明 |
|---|---|
static class |
CachedInputStream.AtBuffers
先使用缓冲区池暂存,再合并到合适的字节数组内
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected byte[] |
m_Cache
缓存
|
protected int |
m_Count
缓存中的数据量(字节数)
|
protected InputStream |
m_Origin
源输入流
|
protected int |
m_Pos
在缓存中读取到的位置
|
protected int |
mark
mark
|
| 构造器和说明 |
|---|
CachedInputStream(InputStream in) |
| 限定符和类型 | 方法和说明 |
|---|---|
int |
available() |
static InputStream |
cached(InputStream in)
若输入流不支持markSupported,缓存其支持mark/reset对流重读取
|
void |
close() |
static int |
copy(InputStream in,
OutputStream out)
由输入流复制到流出流(完成会关闭输入流)
|
int |
count()
当前已缓存的数据量
|
void |
fullyCached()
完全缓存输入流数据
|
Bytes |
getBytes() |
byte[] |
getFitBytes()
取得刚好合适内容的字节数组
|
boolean |
isEof()
源输入流已关闭(或已缓存完整)
|
static boolean |
isUtf8(byte[] bytes,
int len)
检查输入的字符流是否UTF-8字符
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
position()
当前读取到的位置
|
void |
position(int pos)
重定位读取到的位置
|
int |
read() |
int |
read(byte[] b,
int off,
int len) |
static int |
readFully(InputStream in,
byte[] buffer,
int off,
int len)
完整读取需要的数据
|
static String |
readString(InputStream in,
int expect,
int limit,
String charset)
由输入流读取(预期小于8K字节的)指定字符集编码字串
|
static String |
readString(InputStream in,
int expect,
String charset)
由输入流读取(预期小于8K字节的)指定字符集编码字串
|
void |
reset() |
long |
skip(long n) |
static Bytes |
toBytes(InputStream in)
输入流缓存到Bytes
|
static Bytes |
toBytes(InputStream in,
int limit)
输入流缓存到Bytes
|
readprotected InputStream m_Origin
protected int m_Count
protected int m_Pos
protected int mark
protected byte[] m_Cache
public CachedInputStream(InputStream in)
public static InputStream cached(InputStream in)
in - 源输入流public int count()
public int position()
public void position(int pos)
pos - 要重定位的位置(0~count())public int read()
throws IOException
read 在类中 InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read 在类中 InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip 在类中 InputStreamIOExceptionpublic int available()
throws IOException
available 在类中 InputStreamIOExceptionpublic boolean isEof()
public void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 InputStreamIOExceptionpublic void mark(int readlimit)
mark 在类中 InputStreampublic void reset()
throws IOException
reset 在类中 InputStreamIOExceptionpublic boolean markSupported()
markSupported 在类中 InputStreampublic void fullyCached()
throws IOException
IOException - IO异常时抛出public Bytes getBytes()
public byte[] getFitBytes()
public static Bytes toBytes(InputStream in) throws IOException
in - 输入流IOException - IO异常时抛出public static Bytes toBytes(InputStream in, int limit) throws IOException
in - 输入流limit - 若>0则为限制缓存字节数IOException - IO异常时抛出public static String readString(InputStream in, int expect, String charset) throws IOException
in - 输入流expect - 预期的字节数charset - 字符集,如:UTF-8,若指定为null则自动检查是否为utf-8,不是则使用GBKIOException - IO异常时抛出public static String readString(InputStream in, int expect, int limit, String charset) throws IOException
in - 输入流expect - 预期的字节数limit - 限制的字节数(为0则不限制)charset - 字符集,如:UTF-8,若指定为null则自动检查是否为utf-8,不是则使用GBKIOException - IO异常时抛出public static boolean isUtf8(byte[] bytes,
int len)
bytes - 字节数组(字串流)len - 长度(字节)public static int readFully(InputStream in, byte[] buffer, int off, int len) throws IOException
in - 输入流buffer - 读取缓冲区off - 读缓冲区开始位置len - 期望读取的长度IOException - IO异常时抛出public static int copy(InputStream in, OutputStream out) throws IOException
in - 输入流out - 输出流IOException - IO异常时抛出Copyright © 2021. All rights reserved.