PulpCore

pulpcore.net
Class Upload

java.lang.Object
  extended by pulpcore.net.Upload
All Implemented Interfaces:
Runnable

public class Upload
extends Object
implements Runnable

The Upload class represents name/value pairs for sending to an HTTP server via the POST method (multipart form). Values can be either plain text or files.


Constructor Summary
Upload(URL url)
          Creates a new Upload object.
 
Method Summary
 void addField(String name, String value)
          Add a plain text form field to this form.
 void addFields(Map fields)
          Adds plain text form fields to this form.
 void addFile(String name, String fileName, String mimeType, byte[] fileData)
          Add a data file to this form.
 String getResponse()
           
 IOException getUncaughtException()
           
 boolean isCompleted()
           
 void run()
           
 void sendNow()
          Deprecated. Use send(false);
 void start()
          Write the form to an URL via the POST method.
 void start(boolean asynchronous)
          Write the form to an URL via the POST method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Upload

public Upload(URL url)
Creates a new Upload object.

Parameters:
url - the URL to send the POST to.
Method Detail

addFields

public void addFields(Map fields)
Adds plain text form fields to this form.


addField

public void addField(String name,
                     String value)
Add a plain text form field to this form.


addFile

public void addFile(String name,
                    String fileName,
                    String mimeType,
                    byte[] fileData)
Add a data file to this form.


run

public void run()
Specified by:
run in interface Runnable

start

public void start()
Write the form to an URL via the POST method. The form is sent using the multipart/form-data encoding. The response, if any, can be retrieved using getResponse(). This method makes the request asynchronously (returns immediately).


start

public void start(boolean asynchronous)
Write the form to an URL via the POST method. The form is sent using the multipart/form-data encoding. The response, if any, can be retrieved using getResponse().

Parameters:
asynchronous - true for asynchronous operation (the call returns immediately) or false for synchronous operation (the call blocks until the method is complete or an error occurs).

sendNow

public void sendNow()
             throws IOException
Deprecated. Use send(false);

Write the form to an URL via the POST method. The form is sent using the multipart/form-data encoding. The response, if any, can be retrieved using getResponse(). This method blocks until the call is complete or an error occurs.

Throws:
IOException - if an error occurs.

getResponse

public String getResponse()

isCompleted

public boolean isCompleted()
Returns:
true if a call to start() has completed.

getUncaughtException

public IOException getUncaughtException()
Returns:
the uncaught exception during upload, if any.

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.