mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
ff23934b24
commit
2337e3a367
@ -386,7 +386,17 @@ public class IoUtil extends NioUtil {
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public static FastByteArrayOutputStream read(InputStream in, boolean isClose) throws IORuntimeException {
|
||||
final FastByteArrayOutputStream out = new FastByteArrayOutputStream();
|
||||
final FastByteArrayOutputStream out;
|
||||
if(in instanceof FileInputStream){
|
||||
// 文件流的长度是可预见的,此时直接读取效率更高
|
||||
try {
|
||||
out = new FastByteArrayOutputStream(in.available());
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
} else{
|
||||
out = new FastByteArrayOutputStream();
|
||||
}
|
||||
try {
|
||||
copy(in, out);
|
||||
} finally {
|
||||
@ -794,9 +804,23 @@ public class IoUtil extends NioUtil {
|
||||
* @since 4.0.10
|
||||
*/
|
||||
public static BufferedInputStream toBuffered(InputStream in) {
|
||||
Assert.notNull(in, "InputStream must be not null!");
|
||||
return (in instanceof BufferedInputStream) ? (BufferedInputStream) in : new BufferedInputStream(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为{@link BufferedInputStream}
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @param bufferSize buffer size
|
||||
* @return {@link BufferedInputStream}
|
||||
* @since 5.6.1
|
||||
*/
|
||||
public static BufferedInputStream toBuffered(InputStream in, int bufferSize) {
|
||||
Assert.notNull(in, "InputStream must be not null!");
|
||||
return (in instanceof BufferedInputStream) ? (BufferedInputStream) in : new BufferedInputStream(in, bufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为{@link BufferedOutputStream}
|
||||
*
|
||||
@ -805,9 +829,23 @@ public class IoUtil extends NioUtil {
|
||||
* @since 4.0.10
|
||||
*/
|
||||
public static BufferedOutputStream toBuffered(OutputStream out) {
|
||||
Assert.notNull(out, "OutputStream must be not null!");
|
||||
return (out instanceof BufferedOutputStream) ? (BufferedOutputStream) out : new BufferedOutputStream(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为{@link BufferedOutputStream}
|
||||
*
|
||||
* @param out {@link OutputStream}
|
||||
* @param bufferSize buffer size
|
||||
* @return {@link BufferedOutputStream}
|
||||
* @since 5.6.1
|
||||
*/
|
||||
public static BufferedOutputStream toBuffered(OutputStream out, int bufferSize) {
|
||||
Assert.notNull(out, "OutputStream must be not null!");
|
||||
return (out instanceof BufferedOutputStream) ? (BufferedOutputStream) out : new BufferedOutputStream(out, bufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将{@link InputStream}转换为支持mark标记的流<br>
|
||||
* 若原流支持mark标记,则返回原流,否则使用{@link BufferedInputStream} 包装之
|
||||
|
Loading…
x
Reference in New Issue
Block a user