com.monoserv.http
Class HttpBody

java.lang.Object
  extended by com.monoserv.http.HttpBody

public class HttpBody
extends java.lang.Object


Constructor Summary
protected HttpBody()
           
 
Method Summary
 byte[] getData()
          Returns the data that was stored internally for the message body.
 java.lang.String getEncoding()
          Returns the encoding to use
 java.lang.String getStringData()
          Returns the data that was stored internally for the message body as a string.
 boolean isDataString()
          Returns the boolean flag set if the data set inside the HttpBody object if the data is to be used a binary or text
static HttpBody make(byte[] data)
          Creates a base HttpBody object with the supplied data as a byte array in the body.
static HttpBody make(java.lang.String data)
          Creates a base HttpBody object with the supplied data as a byte array in the body.
static HttpBody makeBlank()
          Creates a base HttpBody object with nothing for the body content.
 void setBody(byte[] data)
          This will actually set the internal byte array as the message body
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpBody

protected HttpBody()
Method Detail

makeBlank

public static HttpBody makeBlank()
Creates a base HttpBody object with nothing for the body content. HttpBody obj = new HttpBody(); obj.SetBody(""); return obj;

Returns:
HttpBody A object with nothing in the body

make

public static HttpBody make(byte[] data)
Creates a base HttpBody object with the supplied data as a byte array in the body. HttpBody obj = new HttpBody(); obj.SetBody(data); return obj;

Parameters:
data - The data you want to store as the message body
Returns:
HttpBody An object with the byte array as the data passed for the body,

make

public static HttpBody make(java.lang.String data)
Creates a base HttpBody object with the supplied data as a byte array in the body. This uses the getBytes() from the passed in string data to store the data internally as a byte array. HttpBody obj = new HttpBody(); obj.SetBody(data.getBytes()); return obj;

Parameters:
data - The data you want to store as the message body
Returns:
HttpBody An object with the byte array as the data passed for the body,

setBody

public void setBody(byte[] data)
             throws java.lang.NullPointerException
This will actually set the internal byte array as the message body

Parameters:
data - A byte array containing the raw data to keep as the body.
Throws:
java.lang.NullPointerException - If the supplied data is null.

getData

public byte[] getData()
               throws java.lang.NullPointerException
Returns the data that was stored internally for the message body.

Returns:
byte[] A byte array containing the data stored.
Throws:
java.lang.NullPointerException - If the internal array is null

getStringData

public java.lang.String getStringData()
                               throws java.lang.NullPointerException,
                                      java.io.UnsupportedEncodingException
Returns the data that was stored internally for the message body as a string. Not recommended for binary data. The default charset for encoding is UTF-8.

Returns:
String A string representation of the data.
Throws:
java.lang.NullPointerException - If the internal array is null
java.io.UnsupportedEncodingException

isDataString

public boolean isDataString()
Returns the boolean flag set if the data set inside the HttpBody object if the data is to be used a binary or text

Returns:
boolean true if the data is text, false if its binary

getEncoding

public java.lang.String getEncoding()
Returns the encoding to use

Returns:
String The encoding string to use in this object (Defaults to UTF-8)