|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcds.tools.MultiPartPostOutputStream
public class MultiPartPostOutputStream
Code pour gérer l'upload de fichier en POST (encoding type: multipart/form-data) comme le ferait un browser dans un navigateur
Field Summary | |
---|---|
java.lang.String |
boundary
|
Constructor Summary | |
---|---|
MultiPartPostOutputStream(java.io.OutputStream os,
java.lang.String boundary)
Create a new MultiPartPostOutputStream object |
Method Summary | |
---|---|
void |
close()
Closes the stream. |
static java.lang.String |
createBoundary()
Creates a multipart boundary string by concatenating 20 hyphens (-) and the hexadecimal (base-16) representation of the current time in milliseconds. |
static java.net.URLConnection |
createConnection(java.net.URL url)
Creates a new java.net.URLConnection object from the
specified java.net.URL . |
java.lang.String |
getBoundary()
Gets the multipart boundary string being used by this stream. |
static java.lang.String |
getContentType(java.lang.String boundary)
Gets the content type string suitable for the java.net.URLConnection which includes the multipart
boundary string. |
static void |
setTmpDir(java.lang.String dir)
|
void |
writeField(java.lang.String name,
java.lang.String value)
Writes an string field value. |
void |
writeFile(java.lang.String name,
java.lang.String mimeType,
java.io.File file,
boolean gzip)
Writes a file's contents. |
void |
writeFile(java.lang.String name,
java.lang.String mimeType,
java.lang.String fileName,
byte[] data)
Writes the given bytes. |
void |
writeFile(java.lang.String name,
java.lang.String mimeType,
java.lang.String fileName,
java.io.InputStream is,
boolean gzip)
Writes a input stream's contents. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.lang.String boundary
Constructor Detail |
---|
public MultiPartPostOutputStream(java.io.OutputStream os, java.lang.String boundary)
os
- the output streamboundary
- the boundary. If null, a boundary will be created for youMethod Detail |
---|
public void writeField(java.lang.String name, java.lang.String value) throws java.io.IOException
name
- the field name (required)value
- the field value
java.io.IOException
- on input/output errorspublic void writeFile(java.lang.String name, java.lang.String mimeType, java.io.File file, boolean gzip) throws java.io.IOException
java.lang.IllegalArgumentException
will be thrown.
name
- the field namemimeType
- the file content type (optional, recommended)file
- the file (the file must exist)gzip
- do we compress the file ?
java.io.IOException
- on input/output errorspublic void writeFile(java.lang.String name, java.lang.String mimeType, java.lang.String fileName, java.io.InputStream is, boolean gzip) throws java.io.IOException
java.lang.IllegalArgumentException
will be thrown.
name
- the field namemimeType
- the file content type (optional, recommended)fileName
- the file name (required)is
- the input stream
java.io.IOException
- on input/output errorspublic void writeFile(java.lang.String name, java.lang.String mimeType, java.lang.String fileName, byte[] data) throws java.io.IOException
java.lang.IllegalArgumentException
will be thrown.
name
- the field namemimeType
- the file content type (optional, recommended)fileName
- the file name (required)data
- the file data
java.io.IOException
- on input/output errorspublic void close() throws java.io.IOException
java.io.IOException
- on input/output errorspublic java.lang.String getBoundary()
public static java.net.URLConnection createConnection(java.net.URL url) throws java.io.IOException
java.net.URLConnection
object from the
specified java.net.URL
. This is a convenience method
which will set the doInput
, doOutput
,
useCaches
and defaultUseCaches
fields to
the appropriate settings in the correct order.
java.net.URLConnection
object for the URL
java.io.IOException
- on input/output errorspublic static java.lang.String createBoundary()
getContentType(String)
public static java.lang.String getContentType(java.lang.String boundary)
java.net.URLConnection
which includes the multipart
boundary string. java.net.URLConnection
class, once the output stream
for the connection is acquired, it's too late to set the content
type (or any other request parameter). So one has to create a
multipart boundary string first before using this class, such as
with the createBoundary()
method.
boundary
- the boundary string
createBoundary()
public static void setTmpDir(java.lang.String dir)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |