org.ws4d.java.util
Class MIMEUtil

java.lang.Object
  extended by org.ws4d.java.util.MIMEUtil

public class MIMEUtil
extends java.lang.Object

Utility class for MIME handling.


Field Summary
static int DEFAULT_MIME_BUFFER
           
 
Constructor Summary
MIMEUtil()
           
 
Method Summary
static java.lang.String contentToExtension(java.lang.String mime)
          Returns a file extension that is most likely with given Content-Type
static java.lang.String estimateContentType(java.lang.String filename)
          Gets estimated Content-Type via filename.
static java.lang.String extensionContentType(java.lang.String fileExt)
          Gets Content-Type via file extension.
static boolean readBoundary(java.io.InputStream in, byte[] boundary)
          Reads the boundary string.
static void readHeaderFields(java.io.InputStream in, HashMap headerfields)
          Reads MIME header fields from the input stream.
static void serializeAttachment(java.io.OutputStream out, IncomingAttachment attachment)
           
static void writeBoundary(java.io.OutputStream out, byte[] boundary, boolean crlf, boolean last)
          Writes a MIME boundary.
static void writeHeaderFields(java.io.OutputStream out, HashMap headerfields)
          Writes MIME header fields to the output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIME_BUFFER

public static int DEFAULT_MIME_BUFFER
Constructor Detail

MIMEUtil

public MIMEUtil()
Method Detail

readBoundary

public static boolean readBoundary(java.io.InputStream in,
                                   byte[] boundary)
                            throws java.io.IOException
Reads the boundary string.

Parameters:
in - input stream to read from.
boundary - the given boundary information.
Returns:
the read element.
Throws:
java.io.IOException

writeBoundary

public static void writeBoundary(java.io.OutputStream out,
                                 byte[] boundary,
                                 boolean crlf,
                                 boolean last)
                          throws java.io.IOException
Writes a MIME boundary.

Parameters:
out -
boundary -
crlf -
last -
Throws:
java.io.IOException

serializeAttachment

public static void serializeAttachment(java.io.OutputStream out,
                                       IncomingAttachment attachment)
                                throws java.io.IOException,
                                       AttachmentException
Throws:
java.io.IOException
AttachmentException

writeHeaderFields

public static void writeHeaderFields(java.io.OutputStream out,
                                     HashMap headerfields)
                              throws java.io.IOException
Writes MIME header fields to the output stream.

Parameters:
out -
headerfields -
Throws:
java.io.IOException

readHeaderFields

public static void readHeaderFields(java.io.InputStream in,
                                    HashMap headerfields)
                             throws java.io.IOException,
                                    ProtocolException
Reads MIME header fields from the input stream. To learn more about MIME header fields, take a look at RFC2045 3.

Parameters:
in - the input stream to read from.
headerfields - Hashtable to store the fields in.
Throws:
java.io.IOException
ProtocolException

estimateContentType

public static java.lang.String estimateContentType(java.lang.String filename)
Gets estimated Content-Type via filename.

Parameters:
filename - fileName with extension.
Returns:
Content-Type estimated Content-Type based on the file extension.

contentToExtension

public static java.lang.String contentToExtension(java.lang.String mime)
Returns a file extension that is most likely with given Content-Type

Parameters:
mime - MIME Type
Returns:
Extension probable file extension, "" if Content- Type is unknown

extensionContentType

public static java.lang.String extensionContentType(java.lang.String fileExt)
Gets Content-Type via file extension.

Parameters:
fileExt - file extension.
Returns:
Content-Type (type and subtype).