Streams (Apache Tomcat 8.5.85 API Documentation)

Package org.apache.tomcat.util.http.fileupload.util

## Class Streams

- java.lang.Object
- - org.apache.tomcat.util.http.fileupload.util.Streams

-     public final class Streams
      extends java.lang.Object

  Utility class for working with streams.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `DEFAULT_BUFFER_SIZE` | Default buffer size for use in `copy(InputStream, OutputStream, boolean)`.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static java.lang.String` | `asString​(java.io.InputStream inputStream)` | This convenience method allows to read a `FileItemStream`'s content into a string.
    `static java.lang.String` | `asString​(java.io.InputStream inputStream, java.lang.String encoding)` | This convenience method allows to read a `FileItemStream`'s content into a string, using the given character encoding.
    `static java.lang.String` | `checkFileName​(java.lang.String fileName)` | Checks, whether the given file name is valid in the sense, that it doesn't contain any NUL characters.
    `static long` | `copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeOutputStream)` | Copies the contents of the given `InputStream` to the given `OutputStream`.
    `static long` | `copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeOutputStream, byte[] buffer)` | Copies the contents of the given `InputStream` to the given `OutputStream`.

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### DEFAULT_BUFFER_SIZE

          public static final int DEFAULT_BUFFER_SIZE

      Default buffer size for use in `copy(InputStream, OutputStream, boolean)`.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### copy

          public static long copy​(java.io.InputStream inputStream,
                                  java.io.OutputStream outputStream,
                                  boolean closeOutputStream)
                           throws java.io.IOException

      Copies the contents of the given `InputStream` to the given `OutputStream`. Shortcut for

             copy(pInputStream, pOutputStream, new byte[8192]);

      Parameters:
        `inputStream` - The input stream, which is being read. It is guaranteed, that `InputStream.close()` is called on the stream.
        `outputStream` - The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.
        `closeOutputStream` - True guarantees, that `OutputStream.close()` is called on the stream. False indicates, that only `OutputStream.flush()` should be called finally.
      Returns:
        Number of bytes, which have been copied.
      Throws:
        `java.io.IOException` - An I/O error occurred.

    - #### copy

          public static long copy​(java.io.InputStream inputStream,
                                  java.io.OutputStream outputStream,
                                  boolean closeOutputStream,
                                  byte[] buffer)
                           throws java.io.IOException

      Copies the contents of the given `InputStream` to the given `OutputStream`.
      Parameters:
        `inputStream` - The input stream, which is being read. It is guaranteed, that `InputStream.close()` is called on the stream.
        `outputStream` - The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.
        `closeOutputStream` - True guarantees, that `OutputStream.close()` is called on the stream. False indicates, that only `OutputStream.flush()` should be called finally.
        `buffer` - Temporary buffer, which is to be used for copying data.
      Returns:
        Number of bytes, which have been copied.
      Throws:
        `java.io.IOException` - An I/O error occurred.

    - #### asString

          public static java.lang.String asString​(java.io.InputStream inputStream)
                                           throws java.io.IOException

      This convenience method allows to read a `FileItemStream`'s content into a string. The platform's default character encoding is used for converting bytes into characters.
      Parameters:
        `inputStream` - The input stream to read.
      Returns:
        The streams contents, as a string.
      Throws:
        `java.io.IOException` - An I/O error occurred.
      See Also:
        `asString(InputStream, String)`

    - #### asString

          public static java.lang.String asString​(java.io.InputStream inputStream,
                                                  java.lang.String encoding)
                                           throws java.io.IOException

      This convenience method allows to read a `FileItemStream`'s content into a string, using the given character encoding.
      Parameters:
        `inputStream` - The input stream to read.
        `encoding` - The character encoding, typically "UTF-8".
      Returns:
        The streams contents, as a string.
      Throws:
        `java.io.IOException` - An I/O error occurred.
      See Also:
        `asString(InputStream)`

    - #### checkFileName

          public static java.lang.String checkFileName​(java.lang.String fileName)

      Checks, whether the given file name is valid in the sense, that it doesn't contain any NUL characters. If the file name is valid, it will be returned without any modifications. Otherwise, an `InvalidFileNameException` is raised.
      Parameters:
        `fileName` - The file name to check
      Returns:
        Unmodified file name, if valid.
      Throws:
        `InvalidFileNameException` - The file name was found to be invalid.