Top Description Fields Constructors Methods
org.apache.tomcat.util.http.fileupload.util

public final Class Streams

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, org.apache.tomcat.util.http.fileupload.InvalidFileNameException

Utility class for working with streams.

Field Summary

Modifier and TypeField and Description
public static final int

Constructor Summary

AccessConstructor and Description
private
Streams()

Private constructor, to prevent instantiation.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

Unmodified file name, if valid.
checkFileName
(final String
The file name to check
fileName
)

Checks, whether the given file name is valid in the sense, that it doesn't contain any NUL characters.

public static long

Returns:

Number of bytes, which have been copied.
copy
(final InputStream
The input stream, which is being read. It is guaranteed, that InputStream#close() is called on the stream.
inputStream
,
final OutputStream
The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.
outputStream
,
final boolean
True guarantees, that OutputStream#close() is called on the stream. False indicates, that only OutputStream#flush() should be called finally.
closeOutputStream
)

Copies the contents of the given InputStream to the given OutputStream.

public static long

Returns:

Number of bytes, which have been copied.
copy
(final InputStream
The input stream, which is being read. It is guaranteed, that InputStream#close() is called on the stream.
inputStream
,
final OutputStream
The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.
outputStream
,
final boolean
True guarantees, that OutputStream#close() is called on the stream. False indicates, that only OutputStream#flush() should be called finally.
closeOutputStream
,
final byte[]
Temporary buffer, which is to be used for copying data.
buffer
)

Copies the contents of the given InputStream to the given OutputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE

Default buffer size for use in copy(InputStream, OutputStream, boolean).

Constructor Detail

Streamsback to summary
private Streams()

Private constructor, to prevent instantiation. This class has only static methods.

Method Detail

checkFileNameback to summary
public static String checkFileName(final 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:String

The file name to check

Returns:String

Unmodified file name, if valid.

Exceptions
InvalidFileNameException:
The file name was found to be invalid.
copyback to summary
public static long copy(final InputStream inputStream, final OutputStream outputStream, final boolean closeOutputStream) throws IOException

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

  copy(pInputStream, pOutputStream, new byte[8192]);
Parameters
inputStream:InputStream

The input stream, which is being read. It is guaranteed, that InputStream#close() is called on the stream.

outputStream:OutputStream

The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.

closeOutputStream:boolean

True guarantees, that OutputStream#close() is called on the stream. False indicates, that only OutputStream#flush() should be called finally.

Returns:long

Number of bytes, which have been copied.

Exceptions
IOException:
An I/O error occurred.
copyback to summary
public static long copy(final InputStream inputStream, final OutputStream outputStream, final boolean closeOutputStream, final byte[] buffer) throws IOException

Copies the contents of the given InputStream to the given OutputStream.

Parameters
inputStream:InputStream

The input stream, which is being read. It is guaranteed, that InputStream#close() is called on the stream.

outputStream:OutputStream

The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.

closeOutputStream:boolean

True guarantees, that OutputStream#close() is called on the stream. False indicates, that only OutputStream#flush() should be called finally.

buffer:byte[]

Temporary buffer, which is to be used for copying data.

Returns:long

Number of bytes, which have been copied.

Exceptions
IOException:
An I/O error occurred.