Package com.helger.web.fileupload.parse
Class AbstractFileUploadBase
- java.lang.Object
-
- com.helger.web.fileupload.parse.AbstractFileUploadBase
-
- Direct Known Subclasses:
FileUpload
public abstract class AbstractFileUploadBase extends Object
High level API for processing file uploads.
This class handles multiple files per single HTML widget, sent using
multipart/mixedencoding type, as specified by RFC 1867.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.
- Version:
- $Id: FileUploadBase.java 963609 2010-07-13 06:56:47Z jochen $
- Author:
- Rafal Krzewski, Daniel Rall, Jason van Zyl, John McNally, Martin Cooper, Sean C. Sullivan
-
-
Constructor Summary
Constructors Constructor Description AbstractFileUploadBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected FileItemHeaderscreateFileItemHeaders()Creates a new instance ofIFileItemHeaders.protected byte[]getBoundary(String sContentType)Retrieves the boundary from theContent-typeheader.protected StringgetFieldName(IFileItemHeaders aFileItemHeaders)Retrieves the field name from theContent-dispositionheader.abstract IFileItemFactorygetFileItemFactory()Returns the factory class used when creating file items.protected StringgetFileName(IFileItemHeaders aHeaders)Retrieves the file name from theContent-dispositionheader.longgetFileSizeMax()Returns the maximum allowed size of a single uploaded file, as opposed togetSizeMax().StringgetHeaderEncoding()Retrieves the character encoding used when reading the headers of an individual part.IFileItemIteratorgetItemIterator(IRequestContext aCtx)Processes an RFC 1867 compliantmultipart/form-datastream.protected IFileItemHeadersgetParsedHeaders(String sHeaderPart)Parses theheader-partand returns as key/value pairs.IProgressListenergetProgressListener()Returns the progress listener.longgetSizeMax()Returns the maximum allowed size of a complete request, as opposed togetFileSizeMax().com.helger.commons.collection.impl.ICommonsList<IFileItem>parseRequest(IRequestContext aCtx)Processes an RFC 1867 compliantmultipart/form-datastream.voidsetFileSizeMax(long nFileSizeMax)Sets the maximum allowed size of a single uploaded file, as opposed togetSizeMax().voidsetHeaderEncoding(String sHeaderEncoding)Specifies the character encoding to be used when reading the headers of individual part.voidsetProgressListener(IProgressListener aListener)Sets the progress listener.voidsetSizeMax(long nSizeMax)Sets the maximum allowed size of a complete request, as opposed tosetFileSizeMax(long).
-
-
-
Method Detail
-
getFileItemFactory
@Nonnull public abstract IFileItemFactory getFileItemFactory()
Returns the factory class used when creating file items.- Returns:
- The factory class for new file items.
-
getSizeMax
@CheckForSigned public long getSizeMax()
Returns the maximum allowed size of a complete request, as opposed togetFileSizeMax().- Returns:
- The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.
- See Also:
setSizeMax(long)
-
setSizeMax
public void setSizeMax(long nSizeMax)
Sets the maximum allowed size of a complete request, as opposed tosetFileSizeMax(long).- Parameters:
nSizeMax- The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.- See Also:
getSizeMax()
-
getFileSizeMax
@CheckForSigned public long getFileSizeMax()
Returns the maximum allowed size of a single uploaded file, as opposed togetSizeMax().- Returns:
- Maximum size of a single uploaded file.
- See Also:
setFileSizeMax(long)
-
setFileSizeMax
public void setFileSizeMax(long nFileSizeMax)
Sets the maximum allowed size of a single uploaded file, as opposed togetSizeMax().- Parameters:
nFileSizeMax- Maximum size of a single uploaded file.- See Also:
getFileSizeMax()
-
getHeaderEncoding
@Nullable public String getHeaderEncoding()
Retrieves the character encoding used when reading the headers of an individual part. When not specified, ornull, the request encoding is used. If that is also not specified, ornull, the platform default encoding is used.- Returns:
- The encoding used to read part headers.
-
setHeaderEncoding
public void setHeaderEncoding(@Nullable String sHeaderEncoding)
Specifies the character encoding to be used when reading the headers of individual part. When not specified, ornull, the request encoding is used. If that is also not specified, ornull, the platform default encoding is used.- Parameters:
sHeaderEncoding- The encoding used to read part headers.
-
getProgressListener
@Nullable public IProgressListener getProgressListener()
Returns the progress listener.- Returns:
- The progress listener, if any. Maybe
null.
-
setProgressListener
public void setProgressListener(@Nullable IProgressListener aListener)
Sets the progress listener.- Parameters:
aListener- The progress listener, if any. May be tonull.
-
getItemIterator
@Nonnull public IFileItemIterator getItemIterator(@Nonnull IRequestContext aCtx) throws FileUploadException, IOException
Processes an RFC 1867 compliantmultipart/form-datastream.- Parameters:
aCtx- The context for the request to be parsed.- Returns:
- An iterator to instances of
FileItemStreamparsed from the request, in the order that they were transmitted. - Throws:
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.
-
parseRequest
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<IFileItem> parseRequest(@Nonnull IRequestContext aCtx) throws FileUploadException
Processes an RFC 1867 compliantmultipart/form-datastream.- Parameters:
aCtx- The context for the request to be parsed.- Returns:
- A list of
FileIteminstances parsed from the request, in the order that they were transmitted. - Throws:
FileUploadException- if there are problems reading/parsing the request or storing files.
-
getBoundary
@Nullable protected byte[] getBoundary(@Nonnull String sContentType)
Retrieves the boundary from theContent-typeheader.- Parameters:
sContentType- The value of the content type header from which to extract the boundary value.- Returns:
- The boundary, as a byte array.
-
getFileName
@Nullable protected String getFileName(@Nonnull IFileItemHeaders aHeaders)
Retrieves the file name from theContent-dispositionheader.- Parameters:
aHeaders- The HTTP headers object.- Returns:
- The file name for the current
encapsulation.
-
getFieldName
@Nullable protected String getFieldName(@Nonnull IFileItemHeaders aFileItemHeaders)
Retrieves the field name from theContent-dispositionheader.- Parameters:
aFileItemHeaders- AMapcontaining the HTTP request headers.- Returns:
- The field name for the current
encapsulation.
-
getParsedHeaders
@Nonnull protected IFileItemHeaders getParsedHeaders(@Nonnull String sHeaderPart)
Parses the
header-partand 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:
sHeaderPart- Theheader-partof the currentencapsulation.- Returns:
- A
Mapcontaining the parsed HTTP request headers.
-
createFileItemHeaders
@Nonnull protected FileItemHeaders createFileItemHeaders()
Creates a new instance ofIFileItemHeaders.- Returns:
- The new instance.
-
-