static private HttpStream createStream ( HttpPath path ) throws IOException { String host = path . getHost ( ) ; int port = path . getPort ( ) ; HttpStream stream = null ; long streamTime = 0 ; synchronized ( LOCK ) { if ( _savedStream != null && host . equals ( _savedStream . getHost ( ) ) && port == _savedStream . getPort ( ) ) { stream = _savedStream ; streamTime = _saveTime ; _savedStream = null ; } } if ( stream != null ) { long now ; now = CurrentTime . currentTime ( ) ; if ( now < streamTime + 5000 ) { // if the stream is still valid, use it stream . init ( path ) ; return stream ; } else { // if the stream has timed out, close it try { stream . _isKeepalive = false ; stream . close ( ) ; } catch ( IOException e ) { log . log ( Level . FINE , e . toString ( ) , e ) ; } } } Socket s ; try { s = new Socket ( host , port ) ; if ( path instanceof HttpsPath ) { SSLContext context = SSLContext . getInstance ( "TLS" ) ; javax . net . ssl . TrustManager tm = new javax . net . ssl . X509TrustManager ( ) { public java . security . cert . X509Certificate [ ] getAcceptedIssuers ( ) { return null ; } public void checkClientTrusted ( java . security . cert . X509Certificate [ ] cert , String foo ) { } public void checkServerTrusted ( java . security . cert . X509Certificate [ ] cert , String foo ) { } } ; context . init ( null , new javax . net . ssl . TrustManager [ ] { tm } , null ) ; SSLSocketFactory factory = context . getSocketFactory ( ) ; s = factory . createSocket ( s , host , port , true ) ; } } catch ( ConnectException e ) { throw new ConnectException ( path . getURL ( ) + ": " + e . getMessage ( ) ) ; } catch ( Exception e ) { throw new ConnectException ( path . getURL ( ) + ": " + e . toString ( ) ) ; } int socketTimeout = 300 * 1000 ; try { s . setSoTimeout ( socketTimeout ) ; } catch ( Exception e ) { } return new HttpStream ( path , host , port , s ) ; }
Creates a new HTTP stream . If there is a saved connection to the same host use it .