org.springframework.util

## 类 StreamUtils

- java.lang.Object
- - org.springframework.util.StreamUtils

-     public abstract class StreamUtils
      extends Object

  Simple utility methods for dealing with streams. The copy methods of this class are similar to those defined in `FileCopyUtils` except that all affected streams are left open when done. All copy methods use a block size of 4096 bytes.

  Mainly for use within the framework, but also useful for application code.

  从以下版本开始:
    3.2.2
  作者:
    Juergen Hoeller, Phillip Webb, Brian Clozel
  另请参阅:
    `FileCopyUtils`

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static int` | `BUFFER_SIZE`

  - ### 构造器概要

    构造器
    构造器和说明
    `StreamUtils()`

  - ### 方法概要

    所有方法 静态方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `static void` | `copy(byte[] in, OutputStream out)` Copy the contents of the given byte array to the given OutputStream.
    `static int` | `copy(InputStream in, OutputStream out)` Copy the contents of the given InputStream to the given OutputStream.
    `static void` | `copy(String in, Charset charset, OutputStream out)` Copy the contents of the given String to the given output OutputStream.
    `static long` | `copyRange(InputStream in, OutputStream out, long start, long end)` Copy a range of content of the given InputStream to the given OutputStream.
    `static byte[]` | `copyToByteArray(InputStream in)` Copy the contents of the given InputStream into a new byte array.
    `static String` | `copyToString(InputStream in, Charset charset)` Copy the contents of the given InputStream into a String.
    `static int` | `drain(InputStream in)` Drain the remaining content of the given InputStream.
    `static InputStream` | `emptyInput()` Return an efficient empty `InputStream`.
    `static InputStream` | `nonClosing(InputStream in)` Return a variant of the given `InputStream` where calling `close()` has no effect.
    `static OutputStream` | `nonClosing(OutputStream out)` Return a variant of the given `OutputStream` where calling `close()` has no effect.

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 字段详细资料

    - #### BUFFER_SIZE

          public static final int BUFFER_SIZE

      另请参阅:
        常量字段值

  - ### 构造器详细资料

    - #### StreamUtils

          public StreamUtils()

  - ### 方法详细资料

    - #### copyToByteArray

          public static byte[] copyToByteArray(@Nullable
                                               InputStream in)
                                        throws IOException

      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 be `null` or empty)
      返回:
        the new byte array that has been copied to (possibly empty)
      抛出:
        `IOException` - in case of I/O errors

    - #### copyToString

          public static String copyToString(@Nullable
                                            InputStream in,
                                            Charset charset)
                                     throws IOException

      Copy the contents of the given InputStream into a String. Leaves the stream open when done.
      参数:
        `in` - the InputStream to copy from (may be `null` or empty)
      返回:
        the String that has been copied to (possibly empty)
      抛出:
        `IOException` - in case of I/O errors

    - #### copy

          public static void copy(byte[] in,
                                  OutputStream out)
                           throws IOException

      Copy the contents of the given byte array to the given OutputStream. Leaves the stream open when done.
      参数:
        `in` - the byte array to copy from
        `out` - the OutputStream to copy to
      抛出:
        `IOException` - in case of I/O errors

    - #### copy

          public static void copy(String in,
                                  Charset charset,
                                  OutputStream out)
                           throws IOException

      Copy the contents of the given String to the given output OutputStream. Leaves the stream open when done.
      参数:
        `in` - the String to copy from
        `charset` - the Charset
        `out` - the OutputStream to copy to
      抛出:
        `IOException` - in case of I/O errors

    - #### copy

          public static int copy(InputStream in,
                                 OutputStream out)
                          throws IOException

      Copy the contents of the given InputStream to the given OutputStream. Leaves both streams open when done.
      参数:
        `in` - the InputStream to copy from
        `out` - 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 from
        `out` - the OutputStream to copy to
        `start` - the position to start copying from
        `end` - the position to end copying
      返回:
        the number of bytes copied
      抛出:
        `IOException` - in case of I/O errors
      从以下版本开始:
        4.3

    - #### drain

          public static int drain(InputStream in)
                           throws IOException

      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
      从以下版本开始:
        4.3

    - #### emptyInput

          public static InputStream emptyInput()

      Return an efficient empty `InputStream`.
      返回:
        a `ByteArrayInputStream` based on an empty byte array
      从以下版本开始:
        4.2.2

    - #### nonClosing

          public static InputStream nonClosing(InputStream in)

      Return a variant of the given `InputStream` where calling `close()` has no effect.
      参数:
        `in` - the InputStream to decorate
      返回:
        a version of the InputStream that ignores calls to close

    - #### nonClosing

          public static OutputStream nonClosing(OutputStream out)

      Return a variant of the given `OutputStream` where calling `close()` has no effect.
      参数:
        `out` - the OutputStream to decorate
      返回:
        a version of the OutputStream that ignores calls to close