toolbox.web.util
Class Part

Package class diagram package Part
java.lang.Object
  extended by toolbox.web.util.Part

public class Part
extends java.lang.Object

Class defining a single part of a multipart/form-data request. Provides methods to obtain the content type and contents of a specific part.


Constructor Summary
Part()
          Default constructor.
 
Method Summary
 byte[] getContent()
          Returns the content of this part as a byte array.
 java.lang.String getContentAsString()
          Returns the content of this part as a String
 java.lang.String getContentType()
          Returns the content type of this part.
 java.lang.String getFilename()
          Returns the filename of this part.
 java.lang.String getName()
          Returns the name of this part.
 void setContentType(java.lang.String contentType)
          Set the content type of this part if denotes a part containing file.
 void setFilename(java.lang.String filename)
          Set the filename of this part if it denotes a part containing file.
 void setName(java.lang.String name)
          Set the name of this part.
 void write(byte[] data, int offSet, int len)
          Writes the given byte array to this part.
 void writeTo(java.io.OutputStream os)
          Writes all the contents of this part to the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Part

public Part()
Default constructor. Initialise the ByteArrayOutputStream that will contain the content of this part.

Method Detail

setName

public void setName(java.lang.String name)
Set the name of this part.

Parameters:
name - String containing the name of this part.

getName

public java.lang.String getName()
Returns the name of this part.

Returns:
String containing the name of this part.

setContentType

public void setContentType(java.lang.String contentType)
Set the content type of this part if denotes a part containing file.

Parameters:
contentType - String containing the content type of this part.

getContentType

public java.lang.String getContentType()
Returns the content type of this part. Returns null if this part does not denote a part containing a file.

Returns:
String containing the content type of this part.

setFilename

public void setFilename(java.lang.String filename)
Set the filename of this part if it denotes a part containing file.

Parameters:
filename - String containing the filename of this part.

getFilename

public java.lang.String getFilename()
Returns the filename of this part. Returns null if this part does not denote a part containing a file.

Returns:
String containing the filename of this part.

write

public void write(byte[] data,
                  int offSet,
                  int len)
Writes the given byte array to this part.

Parameters:
data - Byte array containing data to write to this part.
offSet - Start at this position in the array.
len - Stop at this position in the array.

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException
Writes all the contents of this part to the given OutputStream.

Parameters:
os - Write part content to this OutputStream.
Throws:
java.io.IOException - if the write operation fails.

getContent

public byte[] getContent()
Returns the content of this part as a byte array.

Returns:
Byte array containing the content of this part.

getContentAsString

public java.lang.String getContentAsString()
Returns the content of this part as a String

Returns:
String containing the content of this part.