Factory method used to create the {@link Connection}.
@param socket the source socket
@param inputStream the socket input stream
@param outputStream the socket output stream
@return a connection
@throws IOException in case of I/O errors
492875
protected Connection createConnection(Socket socket, InputStream inputStream,
			OutputStream outputStream) throws IOException {
		return new Connection(socket, inputStream, outputStream);
	}
255123
public static void dump(InputStream inputStream) throws IOException
  {
    if(!(inputStream instanceof BufferedInputStream)) {
      inputStream = new BufferedInputStream(inputStream);
    }
    try {
      byte[] buffer = new byte[BUFFER_SIZE];
      int length;
      while((length = inputStream.read(buffer)) != -1) {
        System.out.write(buffer, 0, length);
      }
    }
    finally {
      inputStream.close();
    }
  }
1264155
public Socket connect() throws IOException {
        final Socket socket = this.createSocket();
        final InetAddress destinationAddress = this.getResolvedDestinationAddress();
        final int destinationPort = this.getDestinationPort();
        final SocketAddress destination = new InetSocketAddress(destinationAddress, destinationPort);
        socket.connect(destination);

        return socket;
    }
1221285
private void initSocket()
    throws IOException
  {
    _idleTimeout = _port.getKeepaliveTimeout();

    _port.ssl(_socket);

    writeStream().init(_socket.stream());

    // ReadStream cannot use getWriteStream or auto-flush
    // because of duplex mode
    // ReadStream is = getReadStream();
    _readStream.init(_socket.stream());

    if (log.isLoggable(Level.FINEST)) {
      log.finest(dbgId() + "starting connection " + this
                 + ", total=" + _port.getConnectionCount());
    }
  }
1371061
@Override
	public Socket createSocket(String host, int port) throws IOException,
			UnknownHostException {
		long start = System.currentTimeMillis();
		InetAddress addr = InetAddress.getByName(host);
		long end = System.currentTimeMillis();
		PerformanceLogger.noteElapsed("DNS:" + host, end - start);
		return new Socket(addr, port);
	}
351422
static OutputStream connectToOneServer(String server, int port) throws IOException {
        try {
            Socket pushSocket = new Socket(server, port);
            OutputStream out = pushSocket.getOutputStream();
            m_logger.info("Connected to export endpoint node at: " + server + ":" + port);
            return out;
        } catch (UnknownHostException e) {
            m_logger.rateLimitedLog(120, Level.ERROR, e, "Don't know about host: " + server);
            throw e;
        } catch (IOException e) {
            m_logger.rateLimitedLog(120, Level.ERROR, e, "Couldn't get I/O for the connection to: " + server);
            throw e;
        }
    }
1231155
private ClientConnection createHttpClientConnection(final StreamConnection connection, final OptionMap options, final ByteBufferPool bufferPool) {
		try {
			Class<?> cls = Class.forName("io.undertow.client.http.HttpClientConnection");
			
			Constructor<?> o = cls.getDeclaredConstructor(StreamConnection.class, OptionMap.class, ByteBufferPool.class);
			
			o.setAccessible(true);
			
			return (ClientConnection) o.newInstance(connection, options, bufferPool);			
		}catch(Exception e) {
			logger.error(e.getMessage(), e);
		}

		return null;
	}
1005964
public URLConnection createURLConnection(URL url) throws IOException {
        URLConnection conn = url.openConnection();
		return conn;
	}
305981
private Socket createSocket() throws IOException {
        final ManagedSocketFactory socketFactory = this.socketBindingManager.getSocketFactory();
        final Socket socket = socketFactory.createSocket(this.name);
        // if the outbound binding specifies the source to use, then bind this socket to the
        // appropriate source
        final SocketAddress sourceSocketAddress = this.getOptionalSourceSocketAddress();
        if (sourceSocketAddress != null) {
            socket.bind(sourceSocketAddress);
        }
        return socket;
    }
334364
SocketChannel createSock() throws IOException {
        SocketChannel sock;
        sock = SocketChannel.open();
        sock.configureBlocking(false);
        sock.socket().setSoLinger(false, -1);
        sock.socket().setTcpNoDelay(true);
        return sock;
    }
78058
public java.io.Closeable connect(OutputStream stdin, InputStream stdout, InputStream stderr) {
        setProcessInputStream(stdin);
        setProcessErrorStream(stderr);
        setProcessOutputStream(stdout);
        outputThread.start();
        errorThread.start();
        if (inputThread != null) {
            inputThread.start();
        }
        return new Closeable() {
            @Override
            public void close() {
                stop();
            }
        };
    }
1346259
public static Connection createConnection(final ConnectionFactory connectionFactory) throws LdapException {
        val c = connectionFactory.getConnection();
        if (!c.isOpen()) {
            c.open();
        }
        return c;
    }
259686
private static OutputStream getOutputStream(final Socket socket) throws IOException {
    final OutputStream delegate = socket.getOutputStream();
    return new OutputStream() {

      @Override public void close() throws IOException {
        delegate.flush();
        synchronized (socket) {
          socket.shutdownOutput();
          if (socket.isInputShutdown()) {
            socket.close();
          }
        }
      }
    
      // Boring delegates from here on down
      @Override public void write(int b) throws IOException {
        delegate.write(b);
      }
    
      @Override public void write(byte[] b) throws IOException {
        delegate.write(b);
      }
    
      @Override public void write(byte[] b, int off, int len) throws IOException {
        delegate.write(b, off, len);
      }
    
      @Override public void flush() throws IOException {
        delegate.flush();
      }
    };
  }
406416
@Override
    public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
        final SSLSocketFactory factory = sslCtxt.getSocketFactory();
        final SSLSocket ss = (SSLSocket) factory.createSocket(address, port, localAddress, localPort);

        ss.setEnabledProtocols(protocols);

        return ss;
    }
877881
@Override
  public void close() throws IOException
  {
    SocketChannel s = _s;
    _s = null;
    
    if (s != null) {
      s.close();
    }

    /*
    OutputStream os = _os;
    _os = null;

    InputStream is = _is;
    _is = null;

    try {
      if (os != null)
        os.close();
      
      if (is != null)
        is.close();
    } finally {
      if (s != null)
        s.close();
    }
  */
  }
33162
private WebSocketOutputStream openOutputStream(Socket socket) throws WebSocketException
    {
        try
        {
            // Get the output stream of the socket through which
            // this client sends data to the server.
            return new WebSocketOutputStream(
                new BufferedOutputStream(socket.getOutputStream()));
        }
        catch (IOException e)
        {
            // Failed to get the output stream from the raw socket.
            throw new WebSocketException(
                WebSocketError.SOCKET_OUTPUT_STREAM_FAILURE,
                "Failed to get the output stream from the raw socket: " + e.getMessage(), e);
        }
    }
543317
@Override
    public InputStream openInputStream() throws IOException {
        if (outputStream != null) {
            return new ByteArrayInputStream(outputStream.toByteArray());
        } else {
            return new ByteArrayInputStream(new byte[0]);
        }
    }