private void initialize(URI p_base,String p_uriSpec,boolean allowNonAbsoluteURI) throws MalformedURIException {
  String uriSpec=p_uriSpec;
  int uriSpecLen=(uriSpec != null) ? uriSpec.length() : 0;
  if (p_base == null && uriSpecLen == 0) {
    if (allowNonAbsoluteURI) {
      m_path="";
      return;
    }
    throw new MalformedURIException("Cannot initialize URI with empty parameters.");
  }
  if (uriSpecLen == 0) {
    initialize(p_base);
    return;
  }
  int index=0;
  int colonIdx=uriSpec.indexOf(':');
  if (colonIdx != -1) {
    final int searchFrom=colonIdx - 1;
    int slashIdx=uriSpec.lastIndexOf('/',searchFrom);
    int queryIdx=uriSpec.lastIndexOf('?',searchFrom);
    int fragmentIdx=uriSpec.lastIndexOf('#',searchFrom);
    if (colonIdx == 0 || slashIdx != -1 || queryIdx != -1 || fragmentIdx != -1) {
      if (colonIdx == 0 || (p_base == null && fragmentIdx != 0 && !allowNonAbsoluteURI)) {
        throw new MalformedURIException("No scheme found in URI.");
      }
    }
 else {
      initializeScheme(uriSpec);
      index=m_scheme.length() + 1;
      if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx + 1) == '#') {
        throw new MalformedURIException("Scheme specific part cannot be empty.");
      }
    }
  }
 else   if (p_base == null && uriSpec.indexOf('#') != 0 && !allowNonAbsoluteURI) {
    throw new MalformedURIException("No scheme found in URI.");
  }
  if (((index + 1) < uriSpecLen) && (uriSpec.charAt(index) == '/' && uriSpec.charAt(index + 1) == '/')) {
    index+=2;
    int startPos=index;
    char testChar='\0';
    while (index < uriSpecLen) {
      testChar=uriSpec.charAt(index);
      if (testChar == '/' || testChar == '?' || testChar == '#') {
        break;
      }
      index++;
    }
    if (index > startPos) {
      if (!initializeAuthority(uriSpec.substring(startPos,index))) {
        index=startPos - 2;
      }
    }
 else {
      m_host="";
    }
  }
  initializePath(uriSpec,index);
  if (p_base != null) {
    absolutize(p_base);
  }
}

private void initialize ( URI p_base , String p_uriSpec , boolean allowNonAbsoluteURI ) throws MalformedURIException { String uriSpec = p_uriSpec ; int uriSpecLen = ( uriSpec != null ) ? uriSpec . length ( ) : 0 ; if ( p_base == null && uriSpecLen == 0 ) { if ( allowNonAbsoluteURI ) { m_path = "" ; return ; } throw new MalformedURIException ( "Cannot initialize URI with empty parameters." ) ; } if ( uriSpecLen == 0 ) { initialize ( p_base ) ; return ; } int index = 0 ; int colonIdx = uriSpec . indexOf ( ':' ) ; if ( colonIdx != - 1 ) { final int searchFrom = colonIdx - 1 ; int slashIdx = uriSpec . lastIndexOf ( '/' , searchFrom ) ; int queryIdx = uriSpec . lastIndexOf ( '?' , searchFrom ) ; int fragmentIdx = uriSpec . lastIndexOf ( '#' , searchFrom ) ; if ( colonIdx == 0 || slashIdx != - 1 || queryIdx != - 1 || fragmentIdx != - 1 ) { if ( colonIdx == 0 || ( p_base == null && fragmentIdx != 0 && ! allowNonAbsoluteURI ) ) { throw new MalformedURIException ( "No scheme found in URI." ) ; } } else { initializeScheme ( uriSpec ) ; index = m_scheme . length ( ) + 1 ; if ( colonIdx == uriSpecLen - 1 || uriSpec . charAt ( colonIdx + 1 ) == '#' ) { throw new MalformedURIException ( "Scheme specific part cannot be empty." ) ; } } } else if ( p_base == null && uriSpec . indexOf ( '#' ) != 0 && ! allowNonAbsoluteURI ) { throw new MalformedURIException ( "No scheme found in URI." ) ; } if ( ( ( index + 1 ) < uriSpecLen ) && ( uriSpec . charAt ( index ) == '/' && uriSpec . charAt ( index + 1 ) == '/' ) ) { index += 2 ; int startPos = index ; char testChar = '\0' ; while ( index < uriSpecLen ) { testChar = uriSpec . charAt ( index ) ; if ( testChar == '/' || testChar == '?' || testChar == '#' ) { break ; } index ++ ; } if ( index > startPos ) { if ( ! initializeAuthority ( uriSpec . substring ( startPos , index ) ) ) { index = startPos - 2 ; } } else { m_host = "" ; } } initializePath ( uriSpec , index ) ; if ( p_base != null ) { absolutize ( p_base ) ; } }
initializes this uri from a base uri and a uri specification string . see rfc 2396 section 4 and appendix b for specifications on parsing the uri and section 5 for specifications on resolving relative uris and relative paths .
