if (pos != -1)
while ((tok = in.nextToken()) != StreamTokenizer.TT_EOF) { switch (tok) { case StreamTokenizer.TT_WORD: if (state == 0) { mediaType = in.sval.toLowerCase(); state = MEDIA; break; } if (state == MEDIA) { mediaSubtype = in.sval.toLowerCase(); state = MEDIASUB; break; }  if (state == MEDIASUB || state == PARAM_VALUE) { paramName = in.sval.toLowerCase(); state = PARAM_NAME; break; }  if (state == PARAM_NAME) { String paramValue = in.sval;  if (paramName.equals("charset")) paramValue = paramValue.toLowerCase();  state = PARAM_VALUE; params.put(paramName, paramValue); break; } if (state == COMMENT_START) {  break; } break; case '/':  if (state != MEDIA) throw new IllegalArgumentException();  break; case '=':  if (state != PARAM_NAME) throw new IllegalArgumentException();  break; case ';':  if (state != MEDIASUB && state != PARAM_VALUE) throw new IllegalArgumentException();  break; case '(': lastState = state; state = COMMENT_START; break; case ')': state = lastState; break;  case '"': if (state == PARAM_NAME) { String paramValue = in.sval;  if (paramName.equals("charset")) paramValue = paramValue.toLowerCase();  state = PARAM_VALUE; params.put(paramName, paramValue); break; }   throw new IllegalArgumentException(); default:  throw new IllegalArgumentException(); } } } catch (IOException e)
  private void parseMimeType(String mimeType)  {    // FIXME: This method is know to be not completely correct, but it works for now.        int pos = mimeType.indexOf(';');    if (pos != -1)      {	String tmp = mimeType.substring(pos + 2);	mimeType = mimeType.substring(0, pos);	pos = tmp.indexOf('=');	params.put(tmp.substring(0, pos), tmp.substring(pos + 1));      }    pos = mimeType.indexOf('/');    if (pos == -1)      throw new IllegalArgumentException();    mediaType = mimeType.substring(0, pos);    mediaSubtype = mimeType.substring(pos + 1);  }