core/src/main/java/com/google/cloud/sql/core/CoreSocketFactory.java
public Socket connect(Properties props, String socketPathFormat) throws IOException {
    // Gather parameters
    final String csqlInstanceName = props.getProperty(CLOUD_SQL_INSTANCE_PROPERTY);
    final List<String> ipTypes = listIpTypes(props.getProperty("ipTypes", DEFAULT_IP_TYPES));
    final boolean forceUnixSocket = System.getenv("CLOUD_SQL_FORCE_UNIX_SOCKET") != null;

    // Validate parameters
    Preconditions.checkArgument(
        csqlInstanceName != null,
        "cloudSqlInstance property not set. Please specify this property in the JDBC URL or the "
            + "connection Properties with value in form \"project:region:instance\"");

    // GAE Standard runtimes provide a connection path at "/cloudsql/<CONNECTION_NAME>"
    if (forceUnixSocket || runningOnGaeStandard()) {
      logger.info(
          String.format(
              "Connecting to Cloud SQL instance [%s] via unix socket.", csqlInstanceName));
      UnixSocketAddress socketAddress =
          new UnixSocketAddress(new File(String.format(socketPathFormat, csqlInstanceName)));
      return UnixSocketChannel.open(socketAddress).socket();
    }

    logger.info(
        String.format("Connecting to Cloud SQL instance [%s] via SSL socket.", csqlInstanceName));
    return getInstance().createSslSocket(csqlInstanceName, ipTypes);
  }
public Socket connect(Properties props, String socketPathFormat) throws IOException {
    // Gather parameters
    final String csqlInstanceName = props.getProperty(CLOUD_SQL_INSTANCE_PROPERTY);
    final List<String> ipTypes = listIpTypes(props.getProperty("ipTypes", DEFAULT_IP_TYPES));
    final boolean forceUnixSocket = System.getenv("CLOUD_SQL_FORCE_UNIX_SOCKET") != null;

    // Validate parameters
    Preconditions.checkArgument(
        csqlInstanceName != null,
        "cloudSqlInstance property not set. Please specify this property in the JDBC URL or the "
            + "connection Properties with value in form \"project:region:instance\"");

    // GAE Standard runtimes provide a connection path at "/cloudsql/<CONNECTION_NAME>"
    if (forceUnixSocket || runningOnGaeStandard()) {
      logger.info(
          String.format(
              "Connecting to Cloud SQL instance [%s] via unix socket.", csqlInstanceName));
      UnixSocketAddress socketAddress =
          new UnixSocketAddress(new File(String.format(socketPathFormat, csqlInstanceName)));
      return UnixSocketChannel.open(socketAddress).socket();
    }

    logger.info(
        String.format("Connecting to Cloud SQL instance [%s] via SSL socket.", csqlInstanceName));
    return getInstance().createSslSocket(csqlInstanceName, ipTypes);
  }
public Socket connect ( Properties props , String socketPathFormat ) throws IOException { // Gather parameters final String csqlInstanceName = props . getProperty ( CLOUD_SQL_INSTANCE_PROPERTY ) ; final List < String > ipTypes = listIpTypes ( props . getProperty ( "ipTypes" , DEFAULT_IP_TYPES ) ) ; final boolean forceUnixSocket = System . getenv ( "CLOUD_SQL_FORCE_UNIX_SOCKET" ) != null ; // Validate parameters Preconditions . checkArgument ( csqlInstanceName != null , "cloudSqlInstance property not set. Please specify this property in the JDBC URL or the " + "connection Properties with value in form \"project:region:instance\"" ) ; // GAE Standard runtimes provide a connection path at "/cloudsql/<CONNECTION_NAME>" if ( forceUnixSocket || runningOnGaeStandard ( ) ) { logger . info ( String . format ( "Connecting to Cloud SQL instance [%s] via unix socket." , csqlInstanceName ) ) ; UnixSocketAddress socketAddress = new UnixSocketAddress ( new File ( String . format ( socketPathFormat , csqlInstanceName ) ) ) ; return UnixSocketChannel . open ( socketAddress ) . socket ( ) ; } logger . info ( String . format ( "Connecting to Cloud SQL instance [%s] via SSL socket." , csqlInstanceName ) ) ; return getInstance ( ) . createSslSocket ( csqlInstanceName , ipTypes ) ; }
Creates a socket representing a connection to a Cloud SQL instance.

<p>Depending on the environment, it may return either a SSL Socket or a Unix Socket.

@param props Properties used to configure the connection.
@return the newly created Socket.
@throws IOException if error occurs during socket creation.
Creates a socket representing a connection to a Cloud SQL instance .