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;