public class UploadFile
extends java.lang.Object
This class lets represent a file submitted inline in an HTTP request.
To read this special kind of parameter, an InputStream
must be open. This class lets do it
by its function open()
.
When not used any more this file should be deleted, in order to save server disk space.
This can be easily done thanks to deleteFile()
. This function actually just call the corresponding function
of the file manager, which is the only one to known how to deal with this file on the server. Indeed, even if most
of the time this file is stored on the local file system, it could also be stored on a distant server by a VOSpace.
In this case, the way to proceed is different, hence the use of the file manager.
UWSParameters
,
MultipartParser
Modifier and Type | Field and Description |
---|---|
protected UWSFileManager |
fileManager
File manager to use in order to open, move or delete this uploaded file.
|
java.lang.String |
fileName
File name.
|
long |
length
Length in bytes of the file.
|
protected java.lang.String |
location
Location at which the content of this upload has been stored.
|
java.lang.String |
mimeType
MIME type of the file.
|
protected UWSJob |
owner
Jobs that owns this uploaded file.
|
java.lang.String |
paramName
Name of the parameter in which the file was submitted.
|
protected boolean |
used
Indicate whether this file has been or is used by a UWSJob.
|
Constructor and Description |
---|
UploadFile(java.lang.String paramName,
java.lang.String fileName,
java.lang.String location,
UWSFileManager fileManager)
Build the description of an uploaded file.
|
UploadFile(java.lang.String paramName,
java.lang.String location,
UWSFileManager fileManager)
Build the description of an uploaded file.
|
Modifier and Type | Method and Description |
---|---|
void |
deleteFile()
Delete definitely this uploaded file from the server.
|
java.lang.String |
getLocation()
Get the location (e.g.
|
UWSJob |
getOwner()
Get the job that uses this uploaded file.
|
boolean |
isUsed()
Tell whether this uploaded file has been or will be used.
|
void |
move(UWSJob destination)
Move this uploaded file in a location related to the given
UWSJob . |
java.io.InputStream |
open()
Open a stream toward this uploaded file.
|
java.lang.String |
toString() |
public final java.lang.String paramName
public final java.lang.String fileName
protected java.lang.String location
UWSFileManager
to access its content.protected UWSJob owner
protected boolean used
UploadFile
instance shall be physically deleted from the file system.public java.lang.String mimeType
public long length
protected final UWSFileManager fileManager
public UploadFile(java.lang.String paramName, java.lang.String location, UWSFileManager fileManager)
paramName
- Name of the HTTP request parameter in which the uploaded content was stored. MUST NOT be NULLlocation
- Location of the file on the server. This String is then used by the given file manager in order to open,
move or delete the uploaded file. Thus, it can be a path, an ID or any other String meaningful to the file manager.fileManager
- File manager to use in order to open, move or delete this uploaded file from the server.public UploadFile(java.lang.String paramName, java.lang.String fileName, java.lang.String location, UWSFileManager fileManager)
paramName
- Name of the HTTP request parameter in which the uploaded content was stored. MUST NOT be NULLfileName
- Filename as provided by the HTTP request. MAY be NULLlocation
- Location of the file on the server. This String is then used by the given file manager in order to open,
move or delete the uploaded file. Thus, it can be a path, an ID or any other String meaningful to the file manager.fileManager
- File manager to use in order to open, move or delete this uploaded file from the server.public java.lang.String getLocation()
Get the location (e.g. URI, file path) of this file on the server.
Important note:
This function SHOULD be used only by the UWSFileManager
when open, move and delete operations are executed.
The RequestParser
provided by the library set this location to the file URI (i.e. "file://{local-file-path}")
since the default behavior is to store uploaded file on the system temporary directory.
public UWSJob getOwner()
public final boolean isUsed()
Tell whether this uploaded file has been or will be used.
That's to say, whether an open, delete or move operation has been executed (even if it failed) on this UploadFile
instance.
public java.io.InputStream open() throws java.io.IOException
java.io.IOException
- If an error occurs while opening the stream.UWSFileManager.getUploadInput(UploadFile)
public void deleteFile() throws java.io.IOException
java.io.IOException
- If the delete operation can not be performed.UWSFileManager.deleteUpload(UploadFile)
public void move(UWSJob destination) throws java.io.IOException
Move this uploaded file in a location related to the given UWSJob
.
It is particularly useful if at reception of an HTTP request uploaded files are stored in a temporary
directory (e.g. /tmp on Unix/Linux systems).
This function calls UWSFileManager.moveUpload(UploadFile, UWSJob)
to process to the physical
moving of the file, but it then, it updates its location in this UploadFile
instance.
The file manager does NOT update this location! That's why it must not be called directly, but
through move(UWSJob)
.
destination
- The job by which this uploaded file will be exclusively used.java.io.IOException
- If the move operation can not be performed.UWSFileManager.moveUpload(UploadFile, UWSJob)
public java.lang.String toString()
toString
in class java.lang.Object