516 try {
517 createImpl(stream);
518 if (localAddr != null)
519 bind(localAddr);
520 connect(address);
521 } catch (IOException | IllegalArgumentException | SecurityException e) {
522 try {
523 close();
524 } catch (IOException ce) {
525 e.addSuppressed(ce);
526 }
527 throw e;
528 }
529 }
530
531 /**
532 * Creates the socket implementation.
533 *
534 * @param stream a {@code boolean} value : {@code true} for a TCP socket,
535 * {@code false} for UDP.
536 * @throws IOException if creation fails
537 * @since 1.4
538 */
539 void createImpl(boolean stream) throws SocketException {
540 if (impl == null)
541 setImpl();
542 try {
543 impl.create(stream);
544 created = true;
545 } catch (IOException e) {
546 throw new SocketException(e.getMessage());
547 }
548 }
549
550 void setImpl(SocketImpl si) {
551 impl = si;
552 }
553
554 /**
555 * Sets impl to the system-default type of SocketImpl.
556 * @since 1.4
|
516 try {
517 createImpl(stream);
518 if (localAddr != null)
519 bind(localAddr);
520 connect(address);
521 } catch (IOException | IllegalArgumentException | SecurityException e) {
522 try {
523 close();
524 } catch (IOException ce) {
525 e.addSuppressed(ce);
526 }
527 throw e;
528 }
529 }
530
531 /**
532 * Creates the socket implementation.
533 *
534 * @param stream a {@code boolean} value : {@code true} for a TCP socket,
535 * {@code false} for UDP.
536 * @throws SocketException if creation fails
537 * @since 1.4
538 */
539 void createImpl(boolean stream) throws SocketException {
540 if (impl == null)
541 setImpl();
542 try {
543 impl.create(stream);
544 created = true;
545 } catch (IOException e) {
546 throw new SocketException(e.getMessage());
547 }
548 }
549
550 void setImpl(SocketImpl si) {
551 impl = si;
552 }
553
554 /**
555 * Sets impl to the system-default type of SocketImpl.
556 * @since 1.4
|