int readMessage(byte[] buffer) {
        try {
            int totalBytesRead = 0;
            while (totalBytesRead < buffer.length) {
                int remaining = buffer.length - totalBytesRead;
                int bytesRead = input.read(buffer, totalBytesRead, remaining);
                if (bytesRead == -1) {
                    break;
                }
                totalBytesRead += bytesRead;
            }
            return totalBytesRead;
        } catch (SSLException e) {
            if (e.getCause() instanceof EOFException) {
                return -1;
            }
            throw new RuntimeException(e);
        } catch (ClosedChannelException e) {
            // Thrown for channel-based sockets. Just treat like EOF.
            return -1;
        }  catch (SocketException e) {
            // The socket was broken. Just treat like EOF.
            return -1;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Client-side endpoint. Provides basic services for sending/receiving messages from the client
socket.
benchmark-base/src/main/java/org/conscrypt/ClientEndpoint.java