|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.jdesktop.beans.AbstractBean
org.jdesktop.http.NameValuePair
org.jdesktop.http.Parameter
org.jdesktop.html.form.FileParameter
public class FileParameter extends Parameter
A special Parameter intended to be used as a Form Parameter on a FormRequest for uploading files.
FileParameter adds the contentType and fileName properties. These properties are used to construct the multipart/form-data body of a form request. It is important that the fileName refer to an actual existing file object, and that the contentType be accurate. If either of these two constraints are not met, then the request will likely fail.
The fileName must be formatted such that creating a new File will succeed in locating the file. We use the same rules as the URLConnection class for determining the contentType automatically for the file. In the common case, it will be unnecessary to indicate the contentType manually. However, in special cases you may need to specify the content type manually. The format of the contentType is a mime type, such as text/plain.
If the fileName is correctly specified, then the InputStream returned from getValueStream() will be non-null. You are responsible for closing this stream when finished reading from it.
The "value" of this Parameter is specified to be the fileName. This is enforced by overridding setValue to be a null-op, and by setFilename() calling super.setValue().
| Field Summary | |
|---|---|
private static FileNameMap |
MIMES
|
private String |
contentType
|
private boolean |
contentTypeSetManually
|
private String |
fileName
|
| Fields inherited from class NameValuePair | |
|---|---|
| name, value |
| Constructor Summary | |
FileParameter()
Create a new FileParameter. |
|
FileParameter(String name, File file)
Create a new FileParameter using the given name as the name of this parameter (the key, if you will), and the given File as the file to be uploaded by the FormRequest. |
|
FileParameter(String name, String fileName)
Create a new FileParameter using the given name as the name of this parameter (the key if you will) and the given fileName as the absolute path to the file to be uploaded by the FormRequest. |
|
| Method Summary | |
|---|---|
FileParameter
|
clone()
|
static String
|
computeMimeType(String filename)
Static utility method for computing the mime type based on a filename. |
String
|
getContentType()
Gets the content type of the data being uploaded. |
String
|
getFilename()
Gets the absolute path of the file being uploaded. |
private static FileNameMap
|
getMimeMap()
Static utility method for getting the FileNameMap used to map file names to mime types. |
InputStream
|
getValueStream()
Creates and returns a new InputStream based on the underlying file data. |
void
|
setContentType(String contentType)
Sets the mime-type of the content being uploaded. |
void
|
setFilename(String name)
Sets the absolute path to the file to be uploaded. |
void
|
setValue(String value)
|
| Methods inherited from class Parameter | |
|---|---|
| clone |
| Methods inherited from class NameValuePair | |
|---|---|
| clone, getName, getValue, setName, setValue, toString |
| Methods inherited from class org.jdesktop.beans.AbstractBean | |
|---|---|
| org.jdesktop.beans.AbstractBean#clone(), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(), org.jdesktop.beans.AbstractBean#wait(), org.jdesktop.beans.AbstractBean#wait(long), org.jdesktop.beans.AbstractBean#wait(long, int), org.jdesktop.beans.AbstractBean#equals(java.lang.Object), org.jdesktop.beans.AbstractBean#toString(), org.jdesktop.beans.AbstractBean#hashCode(), org.jdesktop.beans.AbstractBean#getClass(), org.jdesktop.beans.AbstractBean#notify(), org.jdesktop.beans.AbstractBean#notifyAll() |
| Field Detail |
|---|
private static FileNameMap MIMES
private String contentType
private boolean contentTypeSetManually
private String fileName
| Constructor Detail |
|---|
public FileParameter()
public FileParameter(String name, File file)
file - may be null.
public FileParameter(String name, String fileName)
fileName - may be null.
| Method Detail |
|---|
FilePa public FileParameter clone()
static String computeMimeType(String filename)
public final String getContentType()
public final String getFilename()
private static final FileNameMap getMimeMap()
public InputStream getValueStream()
public void setContentType(String contentType)
contentType - if set to null, then the mime type "content/unknown" is
used.
public void setFilename(String name)
@Override public void setValue(String value)
Groovy Documentation