package org.xbib.logging.ext.io;

import java.io.Flushable;
import java.io.IOException;
import java.net.InetAddress;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;

/**
 * An output stream that writes data to a {@link java.net.Socket socket}. Uses {@link
 * SSLSocketFactory#getDefault()} to create the socket.
 */
@SuppressWarnings({"unused", "WeakerAccess"})
public class SslTcpOutputStream extends TcpOutputStream implements AutoCloseable, Flushable {

    /**
     * Creates a SSL TCP output stream.
     * <p/>
     * Uses the {@link SSLSocketFactory#getDefault() default socket factory} to create the socket.
     *
     * @param address the address to connect to
     * @param port    the port to connect to
     * @throws IOException if an I/O error occurs when creating the socket
     */
    public SslTcpOutputStream(final InetAddress address, final int port) throws IOException {
        super(SSLSocketFactory.getDefault(), address, port);
    }

    /**
     * Creates a SSL TCP output stream.
     * <p/>
     * Uses the {@link SSLSocketFactory#getDefault() default socket factory} to create the socket.
     *
     * @param socketFactory the factory used to create the socket
     * @param address       the address to connect to
     * @param port          the port to connect to
     * @throws IOException if an I/O error occurs when creating the socket
     */
    public SslTcpOutputStream(final SocketFactory socketFactory, final InetAddress address, final int port) throws IOException {
        super(socketFactory, address, port);
    }

    /**
     * Creates a SSL TCP output stream.
     * <p/>
     * Uses the {@link SSLSocketFactory#getDefault() default socket factory} to create the socket.
     *
     * @param address          the address to connect to
     * @param port             the port to connect to
     * @param blockOnReconnect {@code true} to block when attempting to reconnect the socket or {@code false} to
     *                         reconnect asynchronously
     * @throws IOException if an I/O error occurs when creating the socket
     */
    public SslTcpOutputStream(final InetAddress address, final int port, final boolean blockOnReconnect) throws IOException {
        super(SSLSocketFactory.getDefault(), address, port, blockOnReconnect);
    }

    /**
     * Creates a SSL TCP output stream.
     * <p/>
     * Uses the {@link SSLSocketFactory#getDefault() default socket factory} to create the socket.
     *
     * @param socketFactory    the factory used to create the socket
     * @param address          the address to connect to
     * @param port             the port to connect to
     * @param blockOnReconnect {@code true} to block when attempting to reconnect the socket or {@code false} to
     *                         reconnect asynchronously
     * @throws IOException if an I/O error occurs when creating the socket
     */
    public SslTcpOutputStream(final SocketFactory socketFactory, final InetAddress address, final int port,
                              final boolean blockOnReconnect) throws IOException {
        super(socketFactory, address, port, blockOnReconnect);
    }
}
