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

public abstract Class FileUploadBase

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.tomcat.util.http.fileupload.FileUpload
Imports
java.io.IOException, java.nio.charset.StandardCharsets, java.util.ArrayList, .List, .Locale, .Map, .Objects, org.apache.tomcat.util.http.fileupload.impl.FileCountLimitExceededException, .FileItemIteratorImpl, .FileUploadIOException, .IOFileUploadException, org.apache.tomcat.util.http.fileupload.util.FileItemHeadersImpl, .Streams

High level API for processing file uploads.

This class handles multiple files per single HTML widget, sent using multipart/mixed encoding type, as specified by RFC 1867. Use parseRequest(RequestContext) to acquire a list of org.apache.tomcat.util.http.fileupload.FileItems associated with a given HTML widget.

How the data for individual parts is stored is determined by the factory used to create them; a given part may be in memory, on disk, or somewhere else.

Field Summary

Modifier and TypeField and Description
public static final String
ATTACHMENT

Content-disposition value for file attachment.

public static final String
CONTENT_DISPOSITION

HTTP content disposition header name.

public static final String
CONTENT_LENGTH

HTTP content length header name.

public static final String
CONTENT_TYPE

HTTP content type header name.

private long
fileCountMax

The maximum permitted number of files that may be uploaded in a single request.

private long
fileSizeMax

The maximum size permitted for a single uploaded file, as opposed to sizeMax.

public static final String
FORM_DATA

Content-disposition value for form data.

private String
headerEncoding

The content encoding to use when reading part headers.

private ProgressListener
listener

The progress listener.

public static final String
MULTIPART

Part of HTTP content type header.

public static final String
MULTIPART_FORM_DATA

HTTP content type header for multipart forms.

public static final String
MULTIPART_MIXED

HTTP content type header for multiple uploads.

private long
sizeMax

The maximum size permitted for the complete request, as opposed to fileSizeMax.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

The boundary, as a byte array.
getBoundary
(final String
The value of the content type header from which to extract the boundary value.
contentType
)

Retrieves the boundary from the Content-type header.

public String

Returns:

The field name for the current encapsulation.
getFieldName
(final FileItemHeaders
A Map containing the HTTP request headers.
headers
)

Retrieves the field name from the Content-disposition header.

private String

Returns:

The field jake
getFieldName
(final String
The content-dispositions header value.
pContentDisposition
)

Returns the field name, which is given by the content-disposition header.

public long

Returns:

The maximum number of files allowed in a single request.
getFileCountMax
()

Returns the maximum number of files allowed in a single request.

public abstract FileItemFactory

Returns:

The factory class for new file items.
getFileItemFactory
()

Returns the factory class used when creating file items.

public String

Returns:

The file name for the current encapsulation.
getFileName
(final FileItemHeaders
The HTTP headers object.
headers
)

Retrieves the file name from the Content-disposition header.

private String

Returns:

The file name
getFileName
(final String
The content-disposition headers value.
pContentDisposition
)

Returns the given content-disposition headers file name.

public long

Returns:

Maximum size of a single uploaded file.
getFileSizeMax
()

Returns the maximum allowed size of a single uploaded file, as opposed to getSizeMax().

public String

Returns:

The encoding used to read part headers.
getHeaderEncoding
()

Retrieves the character encoding used when reading the headers of an individual part.

public FileItemIterator

Returns:

An iterator to instances of FileItemStream parsed from the request, in the order that they were transmitted.
getItemIterator
(final RequestContext
The context for the request to be parsed.
ctx
)

Processes an RFC 1867 compliant multipart/form-data stream.

public FileItemHeaders

Returns:

A Map containing the parsed HTTP request headers.
getParsedHeaders
(final String
The header-part of the current encapsulation.
headerPart
)

Parses the header-part and returns as key/value pairs.

public ProgressListener

Returns:

The progress listener, if any, or null.
getProgressListener
()

Returns the progress listener.

public long

Returns:

The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.
getSizeMax
()

Returns the maximum allowed size of a complete request, as opposed to getFileSizeMax().

protected FileItemHeadersImpl

Returns:

The new instance.
newFileItemHeaders
()

Creates a new instance of FileItemHeaders.

private int

Returns:

Index of the \r\n sequence, which indicates end of line.
parseEndOfLine
(final String
The headers, which are being parsed.
headerPart
,
final int
Index of the last byte, which has yet been processed.
end
)

Skips bytes until the end of the current line.

private void
parseHeaderLine(final FileItemHeadersImpl
String with all headers.
headers
,
final String
Map where to store the current header.
header
)

Reads the next header line.

public List<FileItem>

Returns:

A list of FileItem instances parsed from the request, in the order that they were transmitted.
parseRequest
(final RequestContext
The context for the request to be parsed.
ctx
)

Processes an RFC 1867 compliant multipart/form-data stream.

public void
setFileCountMax(final long
The new limit. -1 means no limit.
fileCountMax
)

Sets the maximum number of files allowed per request.

public abstract void
setFileItemFactory(FileItemFactory
The factory class for new file items.
factory
)

Sets the factory class to use when creating file items.

public void
setFileSizeMax(final long
Maximum size of a single uploaded file.
fileSizeMax
)

Sets the maximum allowed size of a single uploaded file, as opposed to getSizeMax().

public void
setHeaderEncoding(final String
The encoding used to read part headers.
encoding
)

Specifies the character encoding to be used when reading the headers of individual part.

public void
setProgressListener(final ProgressListener
The progress listener, if any. Defaults to null.
pListener
)

Sets the progress listener.

public void
setSizeMax(final long
The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.
sizeMax
)

Sets the maximum allowed size of a complete request, as opposed to setFileSizeMax(long).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTACHMENTback to summary
public static final String ATTACHMENT

Content-disposition value for file attachment.

CONTENT_DISPOSITIONback to summary
public static final String CONTENT_DISPOSITION

HTTP content disposition header name.

CONTENT_LENGTHback to summary
public static final String CONTENT_LENGTH

HTTP content length header name.

CONTENT_TYPEback to summary
public static final String CONTENT_TYPE

HTTP content type header name.

fileCountMaxback to summary
private long fileCountMax

The maximum permitted number of files that may be uploaded in a single request. A value of -1 indicates no maximum.

fileSizeMaxback to summary
private long fileSizeMax

The maximum size permitted for a single uploaded file, as opposed to sizeMax. A value of -1 indicates no maximum.

FORM_DATAback to summary
public static final String FORM_DATA

Content-disposition value for form data.

headerEncodingback to summary
private String headerEncoding

The content encoding to use when reading part headers.

listenerback to summary
private ProgressListener listener

The progress listener.

MULTIPARTback to summary
public static final String MULTIPART

Part of HTTP content type header.

MULTIPART_FORM_DATAback to summary
public static final String MULTIPART_FORM_DATA

HTTP content type header for multipart forms.

MULTIPART_MIXEDback to summary
public static final String MULTIPART_MIXED

HTTP content type header for multiple uploads.

sizeMaxback to summary
private long sizeMax

The maximum size permitted for the complete request, as opposed to fileSizeMax. A value of -1 indicates no maximum.

Constructor Detail

FileUploadBaseback to summary
public FileUploadBase()

Method Detail

getBoundaryback to summary
public byte[] getBoundary(final String contentType)

Retrieves the boundary from the Content-type header.

Parameters
contentType:String

The value of the content type header from which to extract the boundary value.

Returns:byte[]

The boundary, as a byte array.

getFieldNameback to summary
public String getFieldName(final FileItemHeaders headers)

Retrieves the field name from the Content-disposition header.

Parameters
headers:FileItemHeaders

A Map containing the HTTP request headers.

Returns:String

The field name for the current encapsulation.

getFieldNameback to summary
private String getFieldName(final String pContentDisposition)

Returns the field name, which is given by the content-disposition header.

Parameters
pContentDisposition:String

The content-dispositions header value.

Returns:String

The field jake

getFileCountMaxback to summary
public long getFileCountMax()

Returns the maximum number of files allowed in a single request.

Returns:long

The maximum number of files allowed in a single request.

getFileItemFactoryback to summary
public abstract FileItemFactory getFileItemFactory()

Returns the factory class used when creating file items.

Returns:FileItemFactory

The factory class for new file items.

getFileNameback to summary
public String getFileName(final FileItemHeaders headers)

Retrieves the file name from the Content-disposition header.

Parameters
headers:FileItemHeaders

The HTTP headers object.

Returns:String

The file name for the current encapsulation.

getFileNameback to summary
private String getFileName(final String pContentDisposition)

Returns the given content-disposition headers file name.

Parameters
pContentDisposition:String

The content-disposition headers value.

Returns:String

The file name

getFileSizeMaxback to summary
public long getFileSizeMax()

Returns the maximum allowed size of a single uploaded file, as opposed to getSizeMax().

Returns:long

Maximum size of a single uploaded file.

See Also
setFileSizeMax(long)
getHeaderEncodingback to summary
public String getHeaderEncoding()

Retrieves the character encoding used when reading the headers of an individual part. When not specified, or null, the request encoding is used. If that is also not specified, or null, the platform default encoding is used.

Returns:String

The encoding used to read part headers.

getItemIteratorback to summary
public FileItemIterator getItemIterator(final RequestContext ctx) throws FileUploadException, IOException

Processes an RFC 1867 compliant multipart/form-data stream.

Parameters
ctx:RequestContext

The context for the request to be parsed.

Returns:FileItemIterator

An iterator to instances of FileItemStream parsed from the request, in the order that they were transmitted.

Exceptions
FileUploadException:
if there are problems reading/parsing the request or storing files.
IOException:
An I/O error occurred. This may be a network error while communicating with the client or a problem while storing the uploaded content.
getParsedHeadersback to summary
public FileItemHeaders getParsedHeaders(final String headerPart)

Parses the header-part and returns as key/value pairs.

If there are multiple headers of the same names, the name will map to a comma-separated list containing the values.

Parameters
headerPart:String

The header-part of the current encapsulation.

Returns:FileItemHeaders

A Map containing the parsed HTTP request headers.

getProgressListenerback to summary
public ProgressListener getProgressListener()

Returns the progress listener.

Returns:ProgressListener

The progress listener, if any, or null.

getSizeMaxback to summary
public long getSizeMax()

Returns the maximum allowed size of a complete request, as opposed to getFileSizeMax().

Returns:long

The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.

See Also
setSizeMax(long)
newFileItemHeadersback to summary
protected FileItemHeadersImpl newFileItemHeaders()

Creates a new instance of FileItemHeaders.

Returns:FileItemHeadersImpl

The new instance.

parseEndOfLineback to summary
private int parseEndOfLine(final String headerPart, final int end)

Skips bytes until the end of the current line.

Parameters
headerPart:String

The headers, which are being parsed.

end:int

Index of the last byte, which has yet been processed.

Returns:int

Index of the \r\n sequence, which indicates end of line.

parseHeaderLineback to summary
private void parseHeaderLine(final FileItemHeadersImpl headers, final String header)

Reads the next header line.

Parameters
headers:FileItemHeadersImpl

String with all headers.

header:String

Map where to store the current header.

parseRequestback to summary
public List<FileItem> parseRequest(final RequestContext ctx) throws FileUploadException

Processes an RFC 1867 compliant multipart/form-data stream.

Parameters
ctx:RequestContext

The context for the request to be parsed.

Returns:List<FileItem>

A list of FileItem instances parsed from the request, in the order that they were transmitted.

Exceptions
FileUploadException:
if there are problems reading/parsing the request or storing files.
setFileCountMaxback to summary
public void setFileCountMax(final long fileCountMax)

Sets the maximum number of files allowed per request.

Parameters
fileCountMax:long

The new limit. -1 means no limit.

setFileItemFactoryback to summary
public abstract void setFileItemFactory(FileItemFactory factory)

Sets the factory class to use when creating file items.

Parameters
factory:FileItemFactory

The factory class for new file items.

setFileSizeMaxback to summary
public void setFileSizeMax(final long fileSizeMax)

Sets the maximum allowed size of a single uploaded file, as opposed to getSizeMax().

Parameters
fileSizeMax:long

Maximum size of a single uploaded file.

See Also
getFileSizeMax()
setHeaderEncodingback to summary
public void setHeaderEncoding(final String encoding)

Specifies the character encoding to be used when reading the headers of individual part. When not specified, or null, the request encoding is used. If that is also not specified, or null, the platform default encoding is used.

Parameters
encoding:String

The encoding used to read part headers.

setProgressListenerback to summary
public void setProgressListener(final ProgressListener pListener)

Sets the progress listener.

Parameters
pListener:ProgressListener

The progress listener, if any. Defaults to null.

setSizeMaxback to summary
public void setSizeMax(final long sizeMax)

Sets the maximum allowed size of a complete request, as opposed to setFileSizeMax(long).

Parameters
sizeMax:long

The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.

See Also
getSizeMax()