net.livesite.http
Class MultipartForm

java.lang.Object
  extended by net.livesite.http.MultipartForm
All Implemented Interfaces:
Runnable

public class MultipartForm
extends Object
implements Runnable

Assists in submitting multipart/form-data posts. Synopsis: MultipartForm form = new MultipartForm( "http://localhost/test.cgi" ); form.attach( "param_name", "param_value" ); form.attach( "param_name", new File("test.bin") ); form.post();


Constructor Summary
MultipartForm()
          Construct an empty class.
MultipartForm(String post_url)
          Constructs this class.
 
Method Summary
 void attach(String name, ByteArrayInputStream inStream)
          Attach a binary data to the form.
 void attach(String name, File file)
          Attach a file to the form.
 void attach(String name, String value)
          Attach a parameter to the form.
protected  void init()
           
 void post()
          Make the connection and write the data.
 void post(ActionListener listener)
          Make the connection and write the data.
 void run()
          run - Post the form.
 void setLocation(String post_url)
          Set the action argument of the form (submit location).
protected  void writeBinaries(DataOutputStream out)
          Write byte data.
protected  void writeFiles(DataOutputStream out)
          Write file data.
protected  void writeParameters(DataOutputStream out)
          Write parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartForm

public MultipartForm()
Construct an empty class.


MultipartForm

public MultipartForm(String post_url)
Constructs this class.

Parameters:
post_url - String Where to post
Method Detail

init

protected void init()

setLocation

public void setLocation(String post_url)
Set the action argument of the form (submit location).

Parameters:
post_url - String Where to post

attach

public void attach(String name,
                   String value)
            throws Exception
Attach a parameter to the form.

Parameters:
name - String
value - String
Throws:
Exception

attach

public void attach(String name,
                   File file)
            throws Exception
Attach a file to the form.

Parameters:
name - String
file - File
Throws:
Exception

attach

public void attach(String name,
                   ByteArrayInputStream inStream)
            throws Exception
Attach a binary data to the form.

Parameters:
name - String
inStream - ByteArrayInputStream
Throws:
Exception

run

public void run()
run - Post the form. Satifies the Runnable interface. Implemented so that on may set up a MulitpartForm object and then let it post on a separate thread.

Specified by:
run in interface Runnable

post

public void post()
          throws Exception
Make the connection and write the data. All previous methods simply set the stage for this action.

Throws:
Exception

post

public void post(ActionListener listener)
          throws Exception
Make the connection and write the data. All previous methods simply set the stage for this action.

Parameters:
listener - ActionListener Reports progress of the upload.
Throws:
Exception

writeParameters

protected void writeParameters(DataOutputStream out)
                        throws Exception
Write parameters.

Parameters:
out - DataOutputStream
Throws:
Exception

writeFiles

protected void writeFiles(DataOutputStream out)
                   throws Exception
Write file data.

Parameters:
out - DataOutputStream
Throws:
Exception

writeBinaries

protected void writeBinaries(DataOutputStream out)
                      throws Exception
Write byte data.

Parameters:
out - DataOutputStream
Throws:
Exception