类 StreamUtils
java.lang.Object
com.digiwin.dap.middleware.emc.common.utils.StreamUtils
Simple utility methods for dealing with streams.
All affected streams are left open when done.
All copy methods use a block size of 4096 bytes.
- 作者:
- fobgochod
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static voidcopy(byte[] in, OutputStream out) Copy the contents of the given byte array to the given OutputStream.static intcopy(InputStream in, OutputStream out) Copy the contents of the given InputStream to the given OutputStream.static voidcopy(String in, Charset charset, OutputStream out) Copy the contents of the given String to the given OutputStream.static longcopyRange(InputStream in, OutputStream out, long start, long end) Copy a range of content of the given InputStream to the given OutputStream.static byte[]Copy the contents of the given InputStream into a new byte array.static StringcopyToString(ByteArrayOutputStream baos, Charset charset) Copy the contents of the givenByteArrayOutputStreaminto aString.static StringcopyToString(InputStream in, Charset charset) Copy the contents of the given InputStream into a String.static intdrain(InputStream in) Drain the remaining content of the given InputStream.static InputStreamReturn an efficient emptyInputStream.static InputStreamReturn a variant of the givenInputStreamwhere callingclose()has no effect.static OutputStreamnonClosing(OutputStream out) Return a variant of the givenOutputStreamwhere callingclose()has no effect.
-
字段详细资料
-
BUFFER_SIZE
public static final int BUFFER_SIZEThe default buffer size used when copying bytes.- 另请参阅:
-
-
构造器详细资料
-
StreamUtils
public StreamUtils()
-
-
方法详细资料
-
copyToByteArray
Copy the contents of the given InputStream into a new byte array.Leaves the stream open when done.
- 参数:
in- the stream to copy from (may benullor empty)- 返回:
- the new byte array that has been copied to (possibly empty)
- 抛出:
IOException- in case of I/O errors
-
copyToString
Copy the contents of the given InputStream into a String.Leaves the stream open when done.
- 参数:
in- the InputStream to copy from (may benullor empty)charset- theCharsetto use to decode the bytes- 返回:
- the String that has been copied to (possibly empty)
- 抛出:
IOException- in case of I/O errors
-
copyToString
Copy the contents of the givenByteArrayOutputStreaminto aString.This is a more effective equivalent of
new String(baos.toByteArray(), charset).- 参数:
baos- theByteArrayOutputStreamto be copied into a Stringcharset- theCharsetto use to decode the bytes- 返回:
- the String that has been copied to (possibly empty)
-
copy
Copy the contents of the given byte array to the given OutputStream.Leaves the stream open when done.
- 参数:
in- the byte array to copy fromout- the OutputStream to copy to- 抛出:
IOException- in case of I/O errors
-
copy
Copy the contents of the given String to the given OutputStream.Leaves the stream open when done.
- 参数:
in- the String to copy fromcharset- the Charsetout- the OutputStream to copy to- 抛出:
IOException- in case of I/O errors
-
copy
Copy the contents of the given InputStream to the given OutputStream.Leaves both streams open when done.
- 参数:
in- the InputStream to copy fromout- the OutputStream to copy to- 返回:
- the number of bytes copied
- 抛出:
IOException- in case of I/O errors
-
copyRange
public static long copyRange(InputStream in, OutputStream out, long start, long end) throws IOException Copy a range of content of the given InputStream to the given OutputStream.If the specified range exceeds the length of the InputStream, this copies up to the end of the stream and returns the actual number of copied bytes.
Leaves both streams open when done.
- 参数:
in- the InputStream to copy fromout- the OutputStream to copy tostart- the position to start copying fromend- the position to end copying- 返回:
- the number of bytes copied
- 抛出:
IOException- in case of I/O errors
-
drain
Drain the remaining content of the given InputStream.Leaves the InputStream open when done.
- 参数:
in- the InputStream to drain- 返回:
- the number of bytes read
- 抛出:
IOException- in case of I/O errors
-
emptyInput
Return an efficient emptyInputStream.- 返回:
- a
ByteArrayInputStreambased on an empty byte array
-
nonClosing
Return a variant of the givenInputStreamwhere callingclose()has no effect.- 参数:
in- the InputStream to decorate- 返回:
- a version of the InputStream that ignores calls to close
-
nonClosing
Return a variant of the givenOutputStreamwhere callingclose()has no effect.- 参数:
out- the OutputStream to decorate- 返回:
- a version of the OutputStream that ignores calls to close
-