com.ibm.wbi.util
Class MimeObject

java.lang.Object
  |
  +--com.ibm.wbi.util.MimeObject

public class MimeObject
extends java.lang.Object


Constructor Summary
MimeObject()
          Constructs an empty MimeObject.
MimeObject(byte[] buffer, boolean headers_included)
          Constructs a MimeObject by parsing the specified bytes.
MimeObject(byte[] buffer, int offset, int size, boolean headers_included)
          Constructs a MimeObject by parsing the specified bytes.
MimeObject(MimeHeaders h)
          Constructs a MimeObject with the specified headers but with no body.
MimeObject(MimeHeaders h, byte[] body)
          Constructs a MimeObject having the specified headers and body.
MimeObject(java.lang.String boundary, byte[] buffer)
          Constructs a MimeObject of type "multipart/mixed", splitting the specified body using the specified boundary.
MimeObject(java.lang.String boundary, byte[] buffer, int offset, int size)
          Constructs a MimeObject of type "multipart/mixed", splitting the specified body using the specified boundary.
 
Method Summary
protected static void decode24Bits(byte[] bits, byte[] dest, int offset)
          Decode a set of four base64 characters into three eight-bit bytes.
protected static int decode6Bits(char ch)
          Decode the bits represented by one base64 character.
protected static byte[] decodeBase64(byte[] input)
          Decode the base64-encoded input.
protected static byte[] decodeBase64(byte[] input, int offset, int len)
          Decode the base64-encoded input.
protected static void encode24Bits(int bits, int len, byte[] dest, int offset)
          Encode one, two, or three eight-bit bytes into four base64 characters.
protected static byte encode6Bits(int b)
          Encode six bits into one base64 character.
static byte[] encodeBase64(byte[] input)
          Encodes the input into base64.
static byte[] encodeBase64(byte[] input, int offset, int len)
          Encodes the input into base64.
static void enumerateParts(MimeObject o)
           
 byte[] getContent()
          Get the non-multipart content of the MimeObject, decoded if necessary.
 MimeHeaders getHeaders()
          Get the headers of the MimeObject.
 MimeObject getPartByHeader(java.lang.String header_name, java.lang.String desired_value)
          Get a specified subpart of a multipart MimeObject.
 MimeObject getPartByParameter(java.lang.String header_name, java.lang.String parameter_name, java.lang.String desired_value)
          Get a specified subpart of a multipart MimeObject.
 java.util.Vector getParts()
          Get the subparts of the multipart MimeObject.
protected static boolean isBase64Char(byte ch)
          Checks if the specified character is a member of the base64 character set.
static void main(java.lang.String[] argv)
           
static void printByteArray(byte[] arr)
           
static void printByteArrayAsChars(byte[] arr)
           
 void setContent(byte[] buffer, int offset, int size)
          Set the non-multipart content of the MimeObject to the specified bytes.
 void setParts(java.util.Vector pts)
          Set the subparts of the MimeObject.
protected  void splitBodyIntoParts(java.lang.String boundary, byte[] body)
          Splits the specified body into its parts according to the specified boundary, storing the resultant parts in the MimeObjectitself.
protected  void splitBodyIntoParts(java.lang.String boundary, byte[] body, int offset, int size)
          Splits the specified body into its parts according to the specified boundary, storing the resultant parts in the MimeObjectitself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeObject

public MimeObject()
Constructs an empty MimeObject.

MimeObject

public MimeObject(MimeHeaders h)
Constructs a MimeObject with the specified headers but with no body.
Parameters:
h - The specified headers.

MimeObject

public MimeObject(byte[] buffer,
                  boolean headers_included)
Constructs a MimeObject by parsing the specified bytes.
Parameters:
buffer - The bytes to be parsed.
headers_included - Specifies whether buffer includes the MIME headers or only the body. If no headers are included, the object will receive a default type of "text/plain; charset=US-ASCII".

MimeObject

public MimeObject(byte[] buffer,
                  int offset,
                  int size,
                  boolean headers_included)
Constructs a MimeObject by parsing the specified bytes.
Parameters:
buffer - The bytes to be parsed.
offset - The offset within buffer at which parsing should begin.
size - The number of bytes to parse.
headers_included - Specifies whether buffer includes the MIME headers or only the body. If no headers are included, the object will receive a default type of "text/plain; charset=US-ASCII".

MimeObject

public MimeObject(MimeHeaders h,
                  byte[] body)
Constructs a MimeObject having the specified headers and body.
Parameters:
h - The specified headers.
body - The specified body.

MimeObject

public MimeObject(java.lang.String boundary,
                  byte[] buffer)
Constructs a MimeObject of type "multipart/mixed", splitting the specified body using the specified boundary.
Parameters:
boundary - The boundary string.
buffer - The multipart body.

MimeObject

public MimeObject(java.lang.String boundary,
                  byte[] buffer,
                  int offset,
                  int size)
Constructs a MimeObject of type "multipart/mixed", splitting the specified body using the specified boundary.
Parameters:
boundary - The multipart boundary string.
buffer - Contains the body.
offset - The offset within buffer at which the body begins.
size - The length of the body.
Method Detail

splitBodyIntoParts

protected void splitBodyIntoParts(java.lang.String boundary,
                                  byte[] body)
Splits the specified body into its parts according to the specified boundary, storing the resultant parts in the MimeObjectitself.
Parameters:
boundary - The multipart boundary string.
body - The multipart body.

splitBodyIntoParts

protected void splitBodyIntoParts(java.lang.String boundary,
                                  byte[] body,
                                  int offset,
                                  int size)
Splits the specified body into its parts according to the specified boundary, storing the resultant parts in the MimeObjectitself.
Parameters:
boundary - The multipart boundary string.
body - Contains the multipart body.
offset - The offset within body at which the multipart body begins.
size - The length of the multipart body.

getContent

public byte[] getContent()
Get the non-multipart content of the MimeObject, decoded if necessary. Supports 7bit, 8bit, binary, and base64 encodings. Should support quoted-printable.
Returns:
The decoded content.

setContent

public void setContent(byte[] buffer,
                       int offset,
                       int size)
Set the non-multipart content of the MimeObject to the specified bytes.
Parameters:
buffer - Contains the body.
offset - The offset within buffer at which the body begins.
size - The length of the body.

getParts

public java.util.Vector getParts()
Get the subparts of the multipart MimeObject.
Returns:
A Vector of MimeObjects which constitute the subparts of the object.

setParts

public void setParts(java.util.Vector pts)
Set the subparts of the MimeObject.
Parameters:
pts - A Vector of MimeObjects which will constitute the subparts of the object.

getHeaders

public MimeHeaders getHeaders()
Get the headers of the MimeObject.
Returns:
The MIME headers.

getPartByHeader

public MimeObject getPartByHeader(java.lang.String header_name,
                                  java.lang.String desired_value)
                           throws java.util.NoSuchElementException
Get a specified subpart of a multipart MimeObject.
Parameters:
header_name - The header field name to search.
desired_value - The value of header_name which is sought.
Returns:
A MimeObject that has header header_name equal to desired_value.
Throws:
NoSuchElementException - if no subpart of the object has the specified characteristics.

getPartByParameter

public MimeObject getPartByParameter(java.lang.String header_name,
                                     java.lang.String parameter_name,
                                     java.lang.String desired_value)
                              throws java.util.NoSuchElementException
Get a specified subpart of a multipart MimeObject.
Parameters:
header_name - The header field name to search.
parameter_name - The parameter of header_name to search.
desired_value - The value of parameter_name which is sought.
Returns:
A subpart of the object which has parameter parameter_name of header header_name equal to desired_value.
Throws:
NoSuchElementException - if no subpart of the object has the specified characteristics.

isBase64Char

protected static boolean isBase64Char(byte ch)
Checks if the specified character is a member of the base64 character set.
Parameters:
ch - The character.
Returns:
true if the character is a member of the base64 character set, or false otherwise.

decode6Bits

protected static int decode6Bits(char ch)
Decode the bits represented by one base64 character.
Parameters:
ch - One base64 character.
Returns:
The six bits represented by one base64 character, as an int.

decode24Bits

protected static void decode24Bits(byte[] bits,
                                   byte[] dest,
                                   int offset)
Decode a set of four base64 characters into three eight-bit bytes.
Parameters:
bits - The four characters to be decoded, represented as four bytes.
dest - An array of bytes, which must have a length of three, that will receive the decoded bits.

decodeBase64

protected static byte[] decodeBase64(byte[] input)
Decode the base64-encoded input.
Parameters:
input - The input to be decoded.
Returns:
The decoded input.

decodeBase64

protected static byte[] decodeBase64(byte[] input,
                                     int offset,
                                     int len)
Decode the base64-encoded input.
Parameters:
input - Contains the input.
offset - The offset within input at which decoding should start.
len - The number of bytes to decode.
Returns:
The decoded bytes.

encode6Bits

protected static byte encode6Bits(int b)
Encode six bits into one base64 character.
Parameters:
b - The bits to be encoded; b must be less than 64.
Returns:
The encoded bits.

encode24Bits

protected static void encode24Bits(int bits,
                                   int len,
                                   byte[] dest,
                                   int offset)
Encode one, two, or three eight-bit bytes into four base64 characters.
Parameters:
bits - Contains the bits to be encoded in the low-order 24 bits; the other bits must be zero.
len - The number of bytes to encode.
dest - A byte array that will receive the encoded characters.
offset - The offset within dest at which the encoded bytes should be placed.

encodeBase64

public static byte[] encodeBase64(byte[] input)
Encodes the input into base64.
Parameters:
input - The bytes to encode.
Returns:
The encoded bytes.

encodeBase64

public static byte[] encodeBase64(byte[] input,
                                  int offset,
                                  int len)
Encodes the input into base64.
Parameters:
input - Contains the bytes to encode.
offset - The offset within input at which encoding should begin.
len - The number of bytes to encode.
Returns:
The encoded input.

enumerateParts

public static void enumerateParts(MimeObject o)

printByteArray

public static void printByteArray(byte[] arr)

printByteArrayAsChars

public static void printByteArrayAsChars(byte[] arr)

main

public static void main(java.lang.String[] argv)