public class IoUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
默认缓存大小
|
static int |
EOF
数据流末尾
|
| 构造器和说明 |
|---|
IoUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
close(AutoCloseable closeable)
关闭
|
static void |
close(Closeable closeable)
关闭
|
static long |
copy(FileInputStream in,
FileOutputStream out)
拷贝文件流,使用NIO
|
static long |
copy(InputStream in,
OutputStream out)
拷贝流,使用默认Buffer大小
|
static long |
copy(InputStream in,
OutputStream out,
int bufferSize)
拷贝流
|
static long |
copy(InputStream in,
OutputStream out,
int bufferSize,
StreamProgress streamProgress)
拷贝流
|
static long |
copy(ReadableByteChannel in,
WritableByteChannel out,
int bufferSize,
StreamProgress streamProgress)
拷贝流,使用NIO,不会关闭流
|
static long |
copy(Reader reader,
Writer writer)
将Reader中的内容复制到Writer中 使用默认缓存大小
|
static long |
copy(Reader reader,
Writer writer,
int bufferSize)
将Reader中的内容复制到Writer中
|
static long |
copy(Reader reader,
Writer writer,
int bufferSize,
StreamProgress streamProgress)
将Reader中的内容复制到Writer中
|
static long |
copyByNIO(InputStream in,
OutputStream out,
int bufferSize,
StreamProgress streamProgress)
拷贝流
thanks to: https://github.com/venusdrogon/feilong-io/blob/master/src/main/java/com/feilong/io/IOWriteUtil.java
|
static BufferedReader |
getReader(InputStream in,
Charset charset)
获得一个文件读取器
|
static BufferedReader |
getReader(InputStream in,
String charsetName)
获得一个文件读取器
|
static String |
read(FileChannel fileChannel,
Charset charset)
从FileChannel中读取内容
|
static String |
read(FileChannel fileChannel,
String charsetName)
从FileChannel中读取内容
|
static FastByteArrayOutputStream |
read(InputStream in)
从流中读取内容,读到输出流中
|
static String |
read(InputStream in,
Charset charset)
从流中读取内容
|
static String |
read(InputStream in,
String charsetName)
从流中读取内容
|
static String |
read(Reader reader)
从Reader中读取String
|
static byte[] |
readBytes(InputStream in)
从流中读取bytes
|
static byte[] |
readBytes(InputStream in,
int length)
读取指定长度的byte数组
|
static String |
readHex(InputStream in,
int length,
boolean toLowerCase)
读取进制字符串
|
static String |
readHex28Lower(InputStream in)
从流中读取前28个byte并转换为16进制,字母部分使用小写
|
static String |
readHex28Upper(InputStream in)
从流中读取前28个byte并转换为16进制,字母部分使用大写
|
static <T extends Collection<String>> |
readLines(InputStream in,
Charset charset,
T collection)
从流中读取内容
|
static <T extends Collection<String>> |
readLines(InputStream in,
String charsetName,
T collection)
从流中读取内容
|
static <T> T |
readObj(InputStream in)
从流中读取内容,读到输出流中
|
static FileInputStream |
toStream(File file)
文件转为流
|
static ByteArrayInputStream |
toStream(String content,
Charset charset)
String 转为流
|
static ByteArrayInputStream |
toStream(String content,
String charsetName)
String 转为流
|
static void |
write(OutputStream out,
String charset,
boolean isCloseOut,
Object... contents)
将多部分内容写到流中,自动转换为字符串
|
static void |
writeObjects(OutputStream out,
String charset,
boolean isCloseOut,
Serializable... contents)
将多部分内容写到流中
|
public static final int DEFAULT_BUFFER_SIZE
public static final int EOF
public static long copy(Reader reader, Writer writer) throws IOException
reader - Readerwriter - WriterIOExceptionpublic static long copy(Reader reader, Writer writer, int bufferSize) throws IOException
reader - Readerwriter - WriterbufferSize - 缓存大小IOExceptionpublic static long copy(Reader reader, Writer writer, int bufferSize, StreamProgress streamProgress) throws IOException
reader - Readerwriter - WriterbufferSize - 缓存大小IOExceptionpublic static long copy(InputStream in, OutputStream out) throws IOException
in - 输入流out - 输出流IOExceptionpublic static long copy(InputStream in, OutputStream out, int bufferSize) throws IOException
in - 输入流out - 输出流bufferSize - 缓存大小IOExceptionpublic static long copy(InputStream in, OutputStream out, int bufferSize, StreamProgress streamProgress) throws IOException
in - 输入流out - 输出流bufferSize - 缓存大小streamProgress - 进度条IOExceptionpublic static long copyByNIO(InputStream in, OutputStream out, int bufferSize, StreamProgress streamProgress) throws IOException
in - 输入流out - 输出流bufferSize - 缓存大小streamProgress - 进度条IOExceptionpublic static long copy(FileInputStream in, FileOutputStream out) throws IOException
in - 输入out - 输出IOExceptionpublic static long copy(ReadableByteChannel in, WritableByteChannel out, int bufferSize, StreamProgress streamProgress) throws IOException
in - ReadableByteChannelout - WritableByteChannelIOExceptionpublic static BufferedReader getReader(InputStream in, String charsetName) throws IOException
in - 输入流charsetName - 字符集名称IOExceptionpublic static BufferedReader getReader(InputStream in, Charset charset) throws IOException
in - 输入流charset - 字符集IOExceptionpublic static byte[] readBytes(InputStream in) throws IOException
in - InputStreamIOExceptionpublic static byte[] readBytes(InputStream in, int length) throws IOException
in - InputStreamlength - 长度IOExceptionpublic static String readHex(InputStream in, int length, boolean toLowerCase) throws IOException
in - InputStreamlength - 长度toLowerCase - true 传换成小写格式 , false 传换成大写格式IOExceptionpublic static String readHex28Upper(InputStream in) throws IOException
in - InputStreamIOExceptionpublic static String readHex28Lower(InputStream in) throws IOException
in - InputStreamIOExceptionpublic static String read(InputStream in, String charsetName) throws IOException
in - 输入流charsetName - 字符集IOExceptionpublic static String read(InputStream in, Charset charset) throws IOException
in - 输入流charset - 字符集IOExceptionpublic static FastByteArrayOutputStream read(InputStream in) throws IOException
in - 输入流IOExceptionpublic static <T> T readObj(InputStream in) throws IOException
in - 输入流IOExceptionpublic static String read(Reader reader) throws IOException
reader - ReaderIOExceptionpublic static String read(FileChannel fileChannel, String charsetName) throws IOException
fileChannel - 文件管道charsetName - 字符集IOExceptionpublic static String read(FileChannel fileChannel, Charset charset) throws IOException
fileChannel - 文件管道charset - 字符集IOExceptionpublic static <T extends Collection<String>> T readLines(InputStream in, String charsetName, T collection) throws IOException
in - 输入流charsetName - 字符集collection - 返回集合IOExceptionpublic static <T extends Collection<String>> T readLines(InputStream in, Charset charset, T collection) throws IOException
in - 输入流charset - 字符集collection - 返回集合IOExceptionpublic static ByteArrayInputStream toStream(String content, String charsetName)
content - 内容charsetName - 编码public static ByteArrayInputStream toStream(String content, Charset charset)
content - 内容charset - 编码public static FileInputStream toStream(File file)
file - 文件FileInputStreampublic static void write(OutputStream out, String charset, boolean isCloseOut, Object... contents) throws IOException
out - 输出流charset - 写出的内容的字符集isCloseOut - 写入完毕是否关闭输出流contents - 写入的内容,调用toString()方法,不包括不会自动换行IOExceptionpublic static void writeObjects(OutputStream out, String charset, boolean isCloseOut, Serializable... contents) throws IOException
out - 输出流charset - 写出的内容的字符集isCloseOut - 写入完毕是否关闭输出流contents - 写入的内容IOExceptionpublic static void close(Closeable closeable)
closeable - 被关闭的对象public static void close(AutoCloseable closeable)
closeable - 被关闭的对象Copyright © 2017. All rights reserved.