Class Streams
java.lang.Object
org.apache.tomcat.util.http.fileupload.util.Streams
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default buffer size for use incopy(InputStream, OutputStream, boolean)
. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
checkFileName
(String fileName) Checks, whether the given file name is valid in the sense, that it doesn't contain any NUL characters.static long
copy
(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream) Copies the contents of the givenInputStream
to the givenOutputStream
.static long
copy
(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream, byte[] buffer) Copies the contents of the givenInputStream
to the givenOutputStream
.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size for use incopy(InputStream, OutputStream, boolean)
.- See Also:
-
-
Method Details
-
copy
public static long copy(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream) throws IOException Copies the contents of the givenInputStream
to the givenOutputStream
. Shortcut forcopy(pInputStream, pOutputStream, new byte[8192]);
- Parameters:
inputStream
- The input stream, which is being read. It is guaranteed, thatInputStream.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, thatOutputStream.close()
is called on the stream. False indicates, that onlyOutputStream.flush()
should be called finally.- Returns:
- Number of bytes, which have been copied.
- Throws:
IOException
- An I/O error occurred.
-
copy
public static long copy(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream, byte[] buffer) throws IOException Copies the contents of the givenInputStream
to the givenOutputStream
.- Parameters:
inputStream
- The input stream, which is being read. It is guaranteed, thatInputStream.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, thatOutputStream.close()
is called on the stream. False indicates, that onlyOutputStream.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:
IOException
- An I/O error occurred.
-
checkFileName
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, anInvalidFileNameException
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.
-