org.benow.web.applet.upload
Class FolderUploadPost

java.lang.Object
  extended by org.benow.web.applet.upload.FolderUploadPost

public class FolderUploadPost
extends java.lang.Object

Modified from Vlad's excellent code to provide monitorable streaming. Stripped down.

Title: Client HTTP Request class

Description: this class helps to send POST HTTP requests with various form data, including files. Cookies can be added to be included in the request.

Version:
1.0
Author:
Vlad Patryshev
See Also:
http://www.devx.com/Java/Article/17679/1954

Nested Class Summary
static class FolderUploadPost.BinaryParameter
          Used to hold information about a binary part to submit in form.
static interface FolderUploadPost.PostListener
           
 
Constructor Summary
FolderUploadPost(java.lang.String urlString)
          Creates a new multipart POST HTTP request for a specified URL string
FolderUploadPost(java.net.URL url)
          Creates a new multipart POST HTTP request for a specified URL
FolderUploadPost(java.net.URLConnection connection)
          Creates a new multipart POST HTTP request on a freshly opened URLConnection
 
Method Summary
 void addListener(FolderUploadPost.PostListener listener)
           
 void cancel()
           
protected  void newline()
           
 java.io.InputStream post()
          posts the requests to the server, with all the cookies and parameters that were added
protected static java.lang.String randomString()
           
 void setCookie(java.lang.String name, java.lang.String value)
          adds a cookie to the requst
 void setCookies(java.util.Map cookies)
          adds cookies to the request
 void setParameter(FolderUploadPost.BinaryParameter bp)
          adds a file parameter to the request
 void setParameter(java.lang.String name, java.io.File file)
          adds a file parameter to the request
 void setParameter(java.lang.String name, java.lang.Object object)
          adds a parameter to the request; if the parameter is a File, the file is uploaded, otherwise the string value of the parameter is passed in the request
 void setParameter(java.lang.String name, java.lang.String value)
          adds a string parameter to the request
 void throttle()
           
protected  void write(char c)
           
protected  void write(java.lang.String s)
           
protected  void writeln(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FolderUploadPost

public FolderUploadPost(java.net.URLConnection connection)
                 throws java.io.IOException
Creates a new multipart POST HTTP request on a freshly opened URLConnection

Parameters:
connection - an already open URL connection
Throws:
java.io.IOException

FolderUploadPost

public FolderUploadPost(java.net.URL url)
                 throws java.io.IOException
Creates a new multipart POST HTTP request for a specified URL

Parameters:
url - the URL to send request to
Throws:
java.io.IOException

FolderUploadPost

public FolderUploadPost(java.lang.String urlString)
                 throws java.io.IOException
Creates a new multipart POST HTTP request for a specified URL string

Parameters:
urlString - the string representation of the URL to send request to
Throws:
java.io.IOException
Method Detail

write

protected void write(char c)
              throws java.io.IOException
Throws:
java.io.IOException

write

protected void write(java.lang.String s)
              throws java.io.IOException
Throws:
java.io.IOException

newline

protected void newline()
                throws java.io.IOException
Throws:
java.io.IOException

writeln

protected void writeln(java.lang.String s)
                throws java.io.IOException
Throws:
java.io.IOException

randomString

protected static java.lang.String randomString()

cancel

public void cancel()

setCookie

public void setCookie(java.lang.String name,
                      java.lang.String value)
               throws java.io.IOException
adds a cookie to the requst

Parameters:
name - cookie name
value - cookie value
Throws:
java.io.IOException

setCookies

public void setCookies(java.util.Map cookies)
                throws java.io.IOException
adds cookies to the request

Parameters:
cookies - the cookie "name-to-value" map
Throws:
java.io.IOException

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
                  throws java.io.IOException
adds a string parameter to the request

Parameters:
name - parameter name
value - parameter value
Throws:
java.io.IOException

setParameter

public void setParameter(FolderUploadPost.BinaryParameter bp)
                  throws java.io.IOException
adds a file parameter to the request

Parameters:
name - parameter name
filename - the name of the file
is - input stream to read the contents of the file from
Throws:
java.io.IOException

setParameter

public void setParameter(java.lang.String name,
                         java.io.File file)
                  throws java.io.IOException
adds a file parameter to the request

Parameters:
name - parameter name
file - the file to upload
Throws:
java.io.IOException

setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object object)
                  throws java.io.IOException
adds a parameter to the request; if the parameter is a File, the file is uploaded, otherwise the string value of the parameter is passed in the request

Parameters:
name - parameter name
object - parameter value, a File or anything else that can be stringified
Throws:
java.io.IOException

post

public java.io.InputStream post()
                         throws java.io.IOException
posts the requests to the server, with all the cookies and parameters that were added

Returns:
input stream with the server response
Throws:
java.io.IOException

addListener

public void addListener(FolderUploadPost.PostListener listener)

throttle

public void throttle()