public class StreamUtils extends Object
| Constructor and Description |
|---|
StreamUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendWriteAndClose(File f,
String text) |
static BufferedInputStream |
buff(InputStream ins)
为一个输入流包裹一个缓冲流 如果这个输入流本身就是缓冲流,则直接返回
|
static BufferedOutputStream |
buff(OutputStream ops)
为一个输出流包裹一个缓冲流 如果这个输出流本身就是缓冲流,则直接返回
|
static BufferedReader |
buff(Reader reader)
为一个文本输入流包裹一个缓冲流 如果这个输入流本身就是缓冲流,则直接返回
|
static BufferedWriter |
buff(Writer writer)
为一个文本输出流包裹一个缓冲流 如果这个文本输出流本身就是缓冲流,则直接返回
|
static void |
copy(InputStream in,
OutputStream out) |
static void |
copy(InputStream in,
OutputStream out,
byte[] buf) |
static void |
copy(InputStream in,
OutputStream out,
int len) |
static void |
copy(InputStream in,
OutputStream out,
int len,
byte[] buf) |
static void |
copy(InputStream in,
OutputStream out,
int len,
int swapBytes) |
static void |
copy(InputStream in,
OutputStream out,
int len,
int swapBytes,
byte[] buf) |
static boolean |
equals(InputStream ina,
InputStream inb)
判断两个输入流是否严格相等
|
static OutputStream |
fileOut(File file)
根据一个文件建立一个输出流
|
static InputStream |
findFileAsStream(String path,
Class<?> klass,
String enc)
获取输出流
|
static void |
io(Reader in,
Writer out,
int bufferSize) |
static String |
nextLineTrim(BufferedReader br) |
static InputStream |
openFileOrURL(String name) |
static byte[] |
read(InputStream ins)
读取一个输入流中所有的字节
|
static StringBuilder |
read(Reader reader)
从一个文本流中读取全部内容并返回
|
static int |
read(Reader reader,
StringBuilder sb)
从一个文本流中读取全部内容并写入缓冲
|
static String |
readAll(Reader reader)
从一个文本输入流读取所有内容,并将该流关闭
|
static byte[] |
readAndClose(InputStream ins)
读取一个输入流中所有的字节,并关闭输入流
|
static int |
readAndClose(InputStreamReader reader,
StringBuilder sb)
从一个文本流中读取全部内容并写入缓冲
|
static String |
readAndClose(Reader reader)
从一个文本流中读取全部内容并返回
|
static int |
readAvailable(InputStream in,
byte[] b,
int off,
int len) |
static void |
readFully(InputStream in,
byte[] b,
int off,
int len) |
static String |
readText(InputStream in) |
static String |
readText(InputStream in,
String encoding) |
static String |
readText(InputStream in,
String encoding,
int bufferSize) |
static String |
readText(Reader reader) |
static String |
readText(Reader reader,
int bufferSize) |
static boolean |
safeClose(Closeable cb)
关闭一个可关闭对象,可以接受 null 如果成功关闭,返回 true,发生异常 返回 false
|
static void |
safeFlush(Flushable fa)
安全刷新一个可刷新的对象,可接受 null
|
static void |
skipFully(InputStream in,
long n) |
static InputStream |
utf8filte(InputStream in)
判断并移除UTF-8的BOM头
|
static Reader |
utf8r(InputStream is) |
static Writer |
utf8w(OutputStream os) |
static InputStream |
wrap(byte[] bytes) |
static void |
write(OutputStream ops,
byte[] bytes)
将一个字节数组写入一个输出流
|
static long |
write(OutputStream ops,
InputStream ins)
将输入流写入一个输出流 块大小为 8192
|
static long |
write(OutputStream ops,
InputStream ins,
int bufferSize)
将输入流写入一个输出流
|
static void |
write(Writer writer,
CharSequence cs)
将一段文本全部写入一个writer
|
static long |
write(Writer writer,
Reader reader)
将文本输入流写入一个文本输出流 块大小为 8192
|
static void |
writeAndClose(OutputStream ops,
byte[] bytes)
将一个字节数组写入一个输出流
|
static long |
writeAndClose(OutputStream ops,
InputStream ins)
将输入流写入一个输出流 块大小为 8192
|
static long |
writeAndClose(OutputStream ops,
InputStream ins,
int buf) |
static void |
writeAndClose(Writer writer,
CharSequence cs)
将一段文本全部写入一个writer
|
static long |
writeAndClose(Writer writer,
Reader reader)
将文本输入流写入一个文本输出流 块大小为 8192
|
public static boolean equals(InputStream ina, InputStream inb) throws IOException
ina - 输入流inb - 输入流IOException - 异常public static StringBuilder read(Reader reader) throws IOException
注意,它并不会关闭输出流
reader - 文本输出流IOException - 异常public static byte[] read(InputStream ins) throws IOException
ins - 输入流,必须支持 available()IOException - 异常public static int read(Reader reader, StringBuilder sb) throws IOException
reader - 文本输出流sb - 输出的文本缓冲IOException - 异常public static String readAll(Reader reader)
reader - 文本输入流public static String readText(InputStream in) throws IOException
IOExceptionpublic static String readText(InputStream in, String encoding) throws IOException
IOExceptionpublic static String readText(InputStream in, String encoding, int bufferSize) throws IOException
IOExceptionpublic static String readText(Reader reader) throws IOException
IOExceptionpublic static String readText(Reader reader, int bufferSize) throws IOException
IOExceptionpublic static void write(Writer writer, CharSequence cs) throws IOException
注意,它并不会关闭输出流
writer - 操作器cs - 文本IOException - 异常public static long write(OutputStream ops, InputStream ins) throws IOException
注意,它并不会关闭输入/出流
ops - 输出流ins - 输入流IOException - 异常public static long write(OutputStream ops, InputStream ins, int bufferSize) throws IOException
注意,它并不会关闭输入/出流
ops - 输出流ins - 输入流bufferSize - 缓冲块大小IOException - 异常public static long write(Writer writer, Reader reader) throws IOException
注意,它并不会关闭输入/出流
writer - 输出流reader - 输入流IOException - 异常public static void write(OutputStream ops, byte[] bytes) throws IOException
注意,它并不会关闭输出流
ops - 输出流bytes - 字节数组IOException - 异常public static String readAndClose(Reader reader)
reader - 文本输入流public static byte[] readAndClose(InputStream ins)
ins - 输入流,必须支持 available()public static int readAndClose(InputStreamReader reader, StringBuilder sb)
注意,它会关闭输出流
reader - 文本输出流sb - 输出的文本缓冲public static void writeAndClose(Writer writer, CharSequence cs)
注意,它会关闭输出流
writer - 输出流cs - 文本public static long writeAndClose(OutputStream ops, InputStream ins)
注意,它会关闭输入/出流
ops - 输出流ins - 输入流public static long writeAndClose(Writer writer, Reader reader)
注意,它会关闭输入/出流
writer - 输出流reader - 输入流public static void writeAndClose(OutputStream ops, byte[] bytes)
注意,它会关闭输出流
ops - 输出流bytes - 字节数组public static long writeAndClose(OutputStream ops, InputStream ins, int buf)
public static BufferedReader buff(Reader reader)
reader - 文本输入流public static BufferedWriter buff(Writer writer)
writer - 文本输出流public static BufferedInputStream buff(InputStream ins)
ins - 输入流public static BufferedOutputStream buff(OutputStream ops)
ops - 输出流public static void readFully(InputStream in, byte[] b, int off, int len) throws IOException
IOExceptionpublic static void skipFully(InputStream in, long n) throws IOException
IOExceptionpublic static boolean safeClose(Closeable cb)
cb - 可关闭对象public static void safeFlush(Flushable fa)
fa - 可刷新对象public static Reader utf8r(InputStream is)
public static Writer utf8w(OutputStream os)
public static InputStream utf8filte(InputStream in)
in - 输入流public static OutputStream fileOut(File file)
file - 文件public static InputStream wrap(byte[] bytes)
public static InputStream findFileAsStream(String path, Class<?> klass, String enc)
path - 文件路径klass - 参考的类, -- 会用这个类的 ClassLoaderenc - 文件路径编码public static int readAvailable(InputStream in, byte[] b, int off, int len) throws IOException
IOExceptionpublic static String nextLineTrim(BufferedReader br) throws IOException
IOExceptionpublic static void copy(InputStream in, OutputStream out, byte[] buf) throws IOException
IOExceptionpublic static void copy(InputStream in, OutputStream out) throws IOException
IOExceptionpublic static void copy(InputStream in, OutputStream out, int len, byte[] buf) throws IOException
IOExceptionpublic static void copy(InputStream in, OutputStream out, int len) throws IOException
IOExceptionpublic static void copy(InputStream in, OutputStream out, int len, int swapBytes, byte[] buf) throws IOException
IOExceptionpublic static void copy(InputStream in, OutputStream out, int len, int swapBytes) throws IOException
IOExceptionpublic static InputStream openFileOrURL(String name) throws IOException
IOExceptionpublic static void io(Reader in, Writer out, int bufferSize) throws IOException
IOExceptionCopyright © 2020. All rights reserved.