Example usage for java.io EOFException getClass

List of usage examples for java.io EOFException getClass

Introduction

In this page you can find the example usage for java.io EOFException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.maverick.ssl.SSLTransportImpl.java

void processMessages() throws SSLException, EOFException {

    int type = 0;
    byte[] fragment = null;
    try {//from   w  ww .j  a  va 2s . co m
        type = rawIn.read();
        int major = rawIn.read();
        int minor = rawIn.read();

        int length = rawIn.readShort();

        fragment = new byte[length];

        rawIn.readFully(fragment);

        readCipherSuite.decrypt(fragment, 0, fragment.length);

        if (readCipherSuite.getMACLength() > 0) {
            if (!readCipherSuite.verifyMAC(fragment, 0, fragment.length - readCipherSuite.getMACLength(), type,
                    incomingSequence, fragment, fragment.length - readCipherSuite.getMACLength(),
                    readCipherSuite.getMACLength())) {
                throw new SSLException(SSLException.PROTOCOL_VIOLATION,
                        Messages.getString("SSLTransport.invalidMAC")); //$NON-NLS-1$
            }

        }
    } catch (EOFException ex) {
        throw ex;
    } catch (InterruptedIOException ex) {
        throw new SSLException(SSLException.READ_TIMEOUT);
    } catch (IOException ex) {
        throw new SSLException(SSLException.UNEXPECTED_TERMINATION,
                ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage());
    }

    incomingSequence++;

    // #ifdef DEBUG
    log.debug(MessageFormat.format(Messages.getString("SSLTransport.processingFragmentOfType"), //$NON-NLS-1$
            new Object[] { new Integer(type) }));
    // #endif

    switch (type) {
    case SSLHandshakeProtocol.HANDSHAKE_PROTOCOL_MSG:
        handshake.processMessage(fragment, 0, fragment.length - readCipherSuite.getMACLength());
        break;
    case CHANGE_CIPHER_SPEC_MSG:

        // #ifdef DEBUG

        log.debug(Messages.getString("SSLTransport.changingInputCipherSpec")); //$NON-NLS-1$
        // #endif

        readCipherSuite = handshake.getPendingCipherSuite();
        incomingSequence = 0;
        break;
    case ALERT_PROTOCOL:
        switch (fragment[0]) {
        case FATAL_ALERT:
            throw new SSLException(((int) (fragment[1] & 0xFF)));
        case WARNING_ALERT:
            switch (fragment[1]) {
            case SSLException.CLOSE_NOTIFY:

                // #ifdef DEBUG
                log.debug(Messages.getString("SSLTransport.remoteSideClosing")); //$NON-NLS-1$
                // #endif

                sendMessage(ALERT_PROTOCOL,
                        new byte[] { (byte) WARNING_ALERT, (byte) SSLException.CLOSE_NOTIFY });
                // close();
                // Let the InputStream know that we're at EOF
                throw new EOFException();

            default:

                // #ifdef DEBUG
                log.warn(SSLException.getDescription(fragment[1]));
                // #endif

                break;
            }

            break;
        default:

            // #ifdef DEBUG
            log.debug(MessageFormat.format(Messages.getString("SSLTransport.unexpectedAlert"), //$NON-NLS-1$
                    new Object[] { new Integer(fragment[0]), new Integer(fragment[1]) }));
            // #endif

            break;
        }
    case APPLICATION_DATA:
        sslIn.write(fragment, 0, fragment.length - readCipherSuite.getMACLength());
        break;
    default:
        throw new SSLException(SSLException.PROTOCOL_VIOLATION,
                Messages.getString("SSLTransport.unexpecedSSLProtocolType") + type); //$NON-NLS-1$

    }

}