Package jodd.http.upload.impl
Class AdaptiveFileUpload
- java.lang.Object
-
- jodd.http.upload.FileUpload
-
- jodd.http.upload.impl.AdaptiveFileUpload
-
public class AdaptiveFileUpload extends FileUpload
SmartFileUploadimplementation that defer the action of what to do with uploaded file for later. Internally, it stores uploaded file either in memory if it is small, or, in all other cases, it stores them in TEMP folder.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallowFileExtensionsprotected booleanbreakOnErrorprotected byte[]dataprotected java.lang.String[]fileExtensionsprotected intmemoryThresholdprotected java.io.FiletempFileprotected static java.lang.StringTMP_FILE_SUFFIXprotected java.io.FileuploadPath-
Fields inherited from class jodd.http.upload.FileUpload
fileTooBig, header, input, maxFileSize, size, valid
-
-
Constructor Summary
Constructors Constructor Description AdaptiveFileUpload(MultipartRequestInputStream input, int memoryThreshold, java.io.File uploadPath, int maxFileSize, boolean breakOnError, java.lang.String[] extensions, boolean allowed)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckUpload()Determines if upload is allowed.voiddelete()Deletes file uploaded item from disk or memory.byte[]getFileContent()Returns the content of file upload item.java.lang.String[]getFileExtensions()java.io.InputStreamgetFileInputStream()Returns input stream of uploaded file.intgetMemoryThreshold()java.io.FilegetUploadPath()booleanisAllowFileExtensions()booleanisBreakOnError()booleanisInMemory()Returnstrueif file upload resides in memory.protected booleanmatchFileExtension()protected voidprocessStream()Process request input stream.java.io.Filewrite(java.io.File destination)Writes file upload item to destination folder or to destination file.java.io.Filewrite(java.lang.String destination)Writes file uploaded item.-
Methods inherited from class jodd.http.upload.FileUpload
getHeader, getMaxFileSize, getSize, isFileTooBig, isUploaded, isValid, toString
-
-
-
-
Field Detail
-
TMP_FILE_SUFFIX
protected static final java.lang.String TMP_FILE_SUFFIX
- See Also:
- Constant Field Values
-
memoryThreshold
protected final int memoryThreshold
-
uploadPath
protected final java.io.File uploadPath
-
breakOnError
protected final boolean breakOnError
-
fileExtensions
protected final java.lang.String[] fileExtensions
-
allowFileExtensions
protected final boolean allowFileExtensions
-
tempFile
protected java.io.File tempFile
-
data
protected byte[] data
-
-
Constructor Detail
-
AdaptiveFileUpload
AdaptiveFileUpload(MultipartRequestInputStream input, int memoryThreshold, java.io.File uploadPath, int maxFileSize, boolean breakOnError, java.lang.String[] extensions, boolean allowed)
-
-
Method Detail
-
getMemoryThreshold
public int getMemoryThreshold()
-
getUploadPath
public java.io.File getUploadPath()
-
isBreakOnError
public boolean isBreakOnError()
-
getFileExtensions
public java.lang.String[] getFileExtensions()
-
isAllowFileExtensions
public boolean isAllowFileExtensions()
-
isInMemory
public boolean isInMemory()
Returnstrueif file upload resides in memory.- Specified by:
isInMemoryin classFileUpload
-
matchFileExtension
protected boolean matchFileExtension() throws java.io.IOException- Throws:
java.io.IOException
-
checkUpload
protected boolean checkUpload() throws java.io.IOExceptionDetermines if upload is allowed.- Throws:
java.io.IOException
-
processStream
protected void processStream() throws java.io.IOExceptionDescription copied from class:FileUploadProcess request input stream. Note that file size is unknown at this point. Therefore, the implementation should set thesizeattribute after successful processing. This method also must set thevalidattribute.- Specified by:
processStreamin classFileUpload- Throws:
java.io.IOException- See Also:
MultipartRequestInputStream
-
delete
public void delete()
Deletes file uploaded item from disk or memory.
-
write
public java.io.File write(java.lang.String destination) throws java.io.IOExceptionWrites file uploaded item.- Throws:
java.io.IOException
-
write
public java.io.File write(java.io.File destination) throws java.io.IOExceptionWrites file upload item to destination folder or to destination file. Returns the destination file.- Throws:
java.io.IOException
-
getFileContent
public byte[] getFileContent() throws java.io.IOExceptionReturns the content of file upload item.- Specified by:
getFileContentin classFileUpload- Throws:
java.io.IOException
-
getFileInputStream
public java.io.InputStream getFileInputStream() throws java.io.IOExceptionDescription copied from class:FileUploadReturns input stream of uploaded file.- Specified by:
getFileInputStreamin classFileUpload- Throws:
java.io.IOException
-
-