public class MultipartRequest extends ConnectionRequest
PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_REDUNDANT
Constructor and Description |
---|
MultipartRequest()
Initialize variables
|
Modifier and Type | Method and Description |
---|---|
void |
addArgument(String name,
String value)
Add an argument to the request response
|
void |
addArgumentNoEncoding(String key,
String value)
Add an argument to the request response without encoding it, this is useful for
arguments which are already encoded
|
void |
addData(String name,
byte[] data,
String mimeType)
Adds a binary argument to the arguments
|
void |
addData(String name,
InputStream data,
long dataSize,
String mimeType)
Adds a binary argument to the arguments, notice the input stream will be
read only during submission
|
void |
addData(String name,
String filePath,
String mimeType)
Adds a binary argument to the arguments
|
protected void |
buildRequestBody(OutputStream os)
Invoked when send body is true, by default sends the request arguments based
on "POST" conventions
|
protected long |
calculateContentLength() |
String |
getBoundary()
Returns the boundary string which is normally generated based on system time
|
int |
getContentLength()
Returns the content length header value
|
protected void |
initConnection(Object connection)
Invoked to initialize HTTP headers, cookies etc.
|
boolean |
isManualRedirect()
By default redirect responses (302 etc.) are handled manually in multipart requests
|
boolean |
onRedirect(String url)
This is a callback method that been called when there is a redirect.
|
void |
setBoundary(String boundary)
Sets the boundary string, normally you don't need this method.
|
static void |
setCanFlushStream(boolean flush)
Sending large files requires flushing the writer once in a while to prevent
Out Of Memory Errors, Some J2ME implementation are not able to flush the
streams causing the upload to fail.
|
void |
setFilename(String arg,
String filename)
Sets the filename for the given argument
|
void |
setManualRedirect(boolean autoRedirect)
By default redirect responses (302 etc.) are handled manually in multipart requests, set this
to false to handle the redirect.
|
addArgument, addArgument, addRequestHeader, addResponseCodeListener, addResponseListener, cookieReceived, cookieSent, createRequestURL, equals, fireResponseListener, getContentType, getCookieHeader, getDefaultUserAgent, getDestinationFile, getDestinationStorage, getDisposeOnCompletion, getHeader, getHeaderFieldNames, getHeaders, getHttpMethod, getPriority, getResponseCode, getResponseContentType, getResponseData, getResposeCode, getShowOnInit, getSilentRetryCount, getTimeout, getUrl, getUserAgent, getYield, handleErrorResponseCode, handleException, handleIOException, handleRuntimeException, hashCode, hasResponseListeners, initCookieHeader, ioStreamUpdate, isCookiesEnabled, isCookiesEnabledDefault, isDefaultFollowRedirects, isDuplicateSupported, isFailSilently, isFollowRedirects, isKilled, isPausable, isPaused, isPost, isReadRequest, isReadResponseForErrors, isRedirecting, isWriteRequest, kill, pause, postResponse, readErrorCodeHeaders, readHeaders, readResponse, removeAllArguments, removeArgument, removeResponseCodeListener, removeResponseListener, resume, retry, setContentType, setCookieHeader, setCookiesEnabled, setCookiesEnabledDefault, setDefaultFollowRedirects, setDefaultUserAgent, setDestinationFile, setDestinationStorage, setDisposeOnCompletion, setDuplicateSupported, setFailSilently, setFollowRedirects, setHttpMethod, setKilled, setPaused, setPost, setPriority, setReadRequest, setReadResponseForErrors, setShowOnInit, setSilentRetryCount, setTimeout, setUrl, setUseNativeCookieStore, setUserAgent, setWriteRequest, shouldAutoCloseResponse, shouldConvertPostToGetOnRedirect, shouldStop, shouldWriteUTFAsGetBytes, validate
public String getBoundary()
public void setBoundary(String boundary)
boundary
- the boundary stringprotected void initConnection(Object connection)
ConnectionRequest
initConnection
in class ConnectionRequest
connection
- the connection objectpublic void addData(String name, byte[] data, String mimeType)
name
- the name of the datadata
- the data as bytesmimeType
- the mime type for the contentpublic void addData(String name, String filePath, String mimeType) throws IOException
name
- the name of the file datafilePath
- the path of the file to uploadmimeType
- the mime type for the contentIOException
- if the file cannot be openedpublic void addData(String name, InputStream data, long dataSize, String mimeType)
name
- the name of the datadata
- the data streamdataSize
- the byte size of the data stream, if the data stream is a file
the file size can be obtained using the
FileSystemStorage.getInstance().getLength(file) methodmimeType
- the mime type for the contentpublic void setFilename(String arg, String filename)
arg
- the argument namefilename
- the file namepublic void addArgumentNoEncoding(String key, String value)
ConnectionRequest
addArgumentNoEncoding
in class ConnectionRequest
key
- the key of the argumentvalue
- the value for the argumentpublic void addArgument(String name, String value)
ConnectionRequest
addArgument
in class ConnectionRequest
name
- the key of the argumentvalue
- the value for the argumentprotected long calculateContentLength()
protected void buildRequestBody(OutputStream os) throws IOException
ConnectionRequest
buildRequestBody
in class ConnectionRequest
os
- output stream of the bodyIOException
public int getContentLength()
ConnectionRequest
getContentLength
in class ConnectionRequest
public boolean onRedirect(String url)
ConnectionRequest
onRedirect
in class ConnectionRequest
url
- the url to be redirectedpublic boolean isManualRedirect()
public void setManualRedirect(boolean autoRedirect)
autoRedirect
- the autoRedirect to setpublic static void setCanFlushStream(boolean flush)