FileDocCategorySizeDatePackage
MimeMap.javaAPI DocJCIFS 1.3.17 API4365Tue Oct 18 15:26:24 BST 2011jcifs.util

MimeMap

public class MimeMap extends Object

Fields Summary
private static final int
IN_SIZE
private static final int
ST_START
private static final int
ST_COMM
private static final int
ST_TYPE
private static final int
ST_GAP
private static final int
ST_EXT
private byte[]
in
private int
inLen
Constructors Summary
public MimeMap()


        
        int n;

        in = new byte[IN_SIZE];
        InputStream is = getClass().getClassLoader().getResourceAsStream( "jcifs/util/mime.map" );

        inLen = 0;
        while(( n = is.read( in, inLen, IN_SIZE - inLen )) != -1 ) {
            inLen += n;
        }
        if( inLen < 100 || inLen == IN_SIZE ) {
            throw new IOException( "Error reading jcifs/util/mime.map resource" );
        }
        is.close();
    
Methods Summary
public java.lang.StringgetMimeType(java.lang.String extension)

        return getMimeType( extension, "application/octet-stream" );
    
public java.lang.StringgetMimeType(java.lang.String extension, java.lang.String def)

        int state, t, x, i, off;
        byte ch;
        byte[] type = new byte[128];
        byte[] buf = new byte[16];
        byte[] ext = extension.toLowerCase().getBytes( "ASCII" );

        state = ST_START;
        t = x = i = 0;
        for( off = 0; off < inLen; off++ ) {
            ch = in[off];
            switch( state ) {
                case ST_START:
                    if( ch == ' " || ch == '\t" ) {
                        break;
                    } else if( ch == '#" ) {
                        state = ST_COMM;
                        break;
                    }
                    state = ST_TYPE;
                case ST_TYPE:
                    if( ch == ' " || ch == '\t" ) {
                        state = ST_GAP;
                    } else {
                        type[t++] = ch;
                    }
                    break;
                case ST_COMM:
                    if( ch == '\n" ) {
                        t = x = i = 0;
                        state = ST_START;
                    }
                    break;
                case ST_GAP:
                    if( ch == ' " || ch == '\t" ) {
                        break;
                    }
                    state = ST_EXT;
                case ST_EXT:
                    switch( ch ) {
                        case ' ":
                        case '\t":
                        case '\n":
                        case '#":
                            for( i = 0; i < x && x == ext.length && buf[i] == ext[i]; i++ ) {
                                ;
                            }
                            if( i == ext.length ) {
                                return new String( type, 0, t, "ASCII" );
                            }
                            if( ch == '#" ) {
                                state = ST_COMM;
                            } else if( ch == '\n" ) {
                                t = x = i = 0;
                                state = ST_START;
                            }
                            x = 0;
                            break;
                        default:
                            buf[x++] = ch;
                    }
                    break;
            }
        }
        return def;