public Object getURLStreamHandler ( String protocol ) { URLStreamHandler handler = ( URLStreamHandler ) handlers . get ( protocol ) ; if ( handler == null ) { boolean checkedWithFactory = false ; // Use the factory (if any) if ( factory != null ) { handler = factory . createURLStreamHandler ( protocol ) ; checkedWithFactory = true ; } // Try java protocol handler if ( handler == null ) { final String packagePrefixList = System . getProperty ( PROTOCOL_PATH_PROP , "" ) ; StringTokenizer packagePrefixIter = new StringTokenizer ( packagePrefixList , "|" ) ; while ( handler == null && packagePrefixIter . hasMoreTokens ( ) ) { String packagePrefix = packagePrefixIter . nextToken ( ) . trim ( ) ; try { String clsName = packagePrefix + "." + protocol + ".Handler" ; Class < ? > cls = null ; try { ClassLoader cl = ClassLoader . getSystemClassLoader ( ) ; cls = Class . forName ( clsName , true , cl ) ; } catch ( ClassNotFoundException e ) { ClassLoader contextLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( contextLoader != null ) { cls = Class . forName ( clsName , true , contextLoader ) ; } } if ( cls != null ) { handler = ( URLStreamHandler ) cls . newInstance ( ) ; } } catch ( ReflectiveOperationException ignored ) { // Shouldn't happen, but code below handles the error. } } } // Fallback to built-in stream handler. // Makes okhttp the default http/https handler if ( handler == null ) { try { if ( protocol . equals ( "file" ) ) { // https://github.com/google/j2objc/issues/912 handler = new sun . net . www . protocol . file . Handler ( ) ; } else if ( protocol . equals ( "jar" ) ) { throw new UnsupportedOperationException ( "Jar streams are not supported." ) ; } else if ( protocol . equals ( "http" ) ) { handler = new IosHttpHandler ( ) ; } else if ( protocol . equals ( "https" ) ) { try { String name = "com.google.j2objc.net.IosHttpsHandler" ; handler = ( URLStreamHandler ) Class . forName ( name ) . newInstance ( ) ; } catch ( Exception e ) { throw new LibraryNotLinkedError ( "Https support" , "jre_ssl" , "JavaxNetSslHttpsURLConnection" ) ; } } } catch ( Exception e ) { throw new AssertionError ( e ) ; } } synchronized ( streamHandlerLock ) { URLStreamHandler handler2 = null ; // Check again with hashtable just in case another // thread created a handler since we last checked handler2 = ( URLStreamHandler ) handlers . get ( protocol ) ; if ( handler2 != null ) { return handler2 ; } // Check with factory if another thread set a // factory since our last check if ( ! checkedWithFactory && factory != null ) { handler2 = factory . createURLStreamHandler ( protocol ) ; } if ( handler2 != null ) { // The handler from the factory must be given more // importance. Discard the default handler that // this thread created. handler = handler2 ; } // Insert this handler into the hashtable if ( handler != null ) { handlers . put ( protocol , handler ) ; } } } return handler ; }
Returns the Stream Handler .