mil.dod.th.ose.remote/src/mil/dod/th/ose/remote/SocketMessageListener.java
private byte[] readMessage() throws RemoteInterfaceException
    {
        final byte[] messageBuffer;
        try
        {
            // first read size of message coming in
            final int firstByte;
            try
            {
                firstByte = m_InputStream.read();
            }
            catch (final SocketException e)
            {
                // socket has been closed, just return so the thread can exit
                return null;
            }
                        
            if (firstByte == -1)
            {
                // reached EOF
                m_Logging.info("Socket %s closed, will stop reading from it", 
                        m_Socket.getRemoteSocketAddress());
                return null;
            }
            final int messageSize = CodedInputStream.readRawVarint32(firstByte, m_InputStream);
            
            if (messageSize > m_RemoteSettings.getMaxMessageSize())
            {
                throw new RemoteInterfaceException(
                        String.format("Message over Max Size: %s > %s", 
                                messageSize, m_RemoteSettings.getMaxMessageSize()));
            }
            
            if (m_RemoteSettings.isLogRemoteMessagesEnabled())
            {
                m_Logging.debug("New message of size %d for socket %s", messageSize,
                    m_Socket.getRemoteSocketAddress());
            }
            
            // now read in message
            messageBuffer = new byte[messageSize];
            int bytesRemaining = messageSize;
            while (bytesRemaining > 0)
            {
                final int bytesRead = m_InputStream.read(messageBuffer, messageSize - bytesRemaining, 
                        bytesRemaining);
                if (bytesRead == -1)
                {
                    // reached EOF
                    m_Logging.error("Socket %s closed while reading message, will stop reading from it", 
                            m_Socket.getRemoteSocketAddress());
                    return null;
                }
                m_AllBytesReceived += bytesRead;
                m_Channel.setBytesReceived(m_AllBytesReceived);
                bytesRemaining -= bytesRead;
            }
            
        }
        catch (final IOException e)
        {
            m_Logging.error(e, "Failed to read message from the input stream for socket %s", 
                    m_Socket.getRemoteSocketAddress());
            return null;
        }
        return messageBuffer;
    }
/**
     * Read a single {@link TerraHarvestMessage} from the input stream with an octet count of the message size before
     * the message.
     * 
     * @return
     *      array containing the {@link TerraHarvestMessage} (does not include the octet count) or null if no message
     * @throws RemoteInterfaceException An error with the size of the message.
     */
Read a single  TerraHarvestMessage from the input stream with an octet count of the message size before
the message.

@return
array containing the  TerraHarvestMessage (does not include the octet count) or null if no message
@throws RemoteInterfaceException An error with the size of the message.
Read a single TerraHarvestMessage from the input stream with an octet count of the message size before the message . @return array containing the TerraHarvestMessage ( does not include the octet count ) or null if no message @throws RemoteInterfaceException An error with the size of the message .
private byte[] readMessage() throws RemoteInterfaceException
    {
        final byte[] messageBuffer;
        try
        {
            final int firstByte;
            try
            {
                firstByte = m_InputStream.read();
            }
            catch (final SocketException e)
            {
                return null;
            }
            if (firstByte == -1)
            {
                m_Logging.info("Socket %s closed, will stop reading from it", 
                        m_Socket.getRemoteSocketAddress());
                return null;
            }
            final int messageSize = CodedInputStream.readRawVarint32(firstByte, m_InputStream);
            if (messageSize > m_RemoteSettings.getMaxMessageSize())
            {
                throw new RemoteInterfaceException(
                        String.format("Message over Max Size: %s > %s", 
                                messageSize, m_RemoteSettings.getMaxMessageSize()));
            }
            if (m_RemoteSettings.isLogRemoteMessagesEnabled())
            {
                m_Logging.debug("New message of size %d for socket %s", messageSize,
                    m_Socket.getRemoteSocketAddress());
            }
            messageBuffer = new byte[messageSize];
            int bytesRemaining = messageSize;
            while (bytesRemaining > 0)
            {
                final int bytesRead = m_InputStream.read(messageBuffer, messageSize - bytesRemaining, 
                        bytesRemaining);
                if (bytesRead == -1)
                {
                    m_Logging.error("Socket %s closed while reading message, will stop reading from it", 
                            m_Socket.getRemoteSocketAddress());
                    return null;
                }
                m_AllBytesReceived += bytesRead;
                m_Channel.setBytesReceived(m_AllBytesReceived);
                bytesRemaining -= bytesRead;
            }
        }
        catch (final IOException e)
        {
            m_Logging.error(e, "Failed to read message from the input stream for socket %s", 
                    m_Socket.getRemoteSocketAddress());
            return null;
        }
        return messageBuffer;
    }
private byte [ ] readMessage ( ) throws RemoteInterfaceException { final byte [ ] messageBuffer ; try { final int firstByte ; try { firstByte = m_InputStream . read ( ) ; } catch ( final SocketException e ) { return null ; } if ( firstByte == - 1 ) { m_Logging . info ( "Socket %s closed, will stop reading from it" , m_Socket . getRemoteSocketAddress ( ) ) ; return null ; } final int messageSize = CodedInputStream . readRawVarint32 ( firstByte , m_InputStream ) ; if ( messageSize > m_RemoteSettings . getMaxMessageSize ( ) ) { throw new RemoteInterfaceException ( String . format ( "Message over Max Size: %s > %s" , messageSize , m_RemoteSettings . getMaxMessageSize ( ) ) ) ; } if ( m_RemoteSettings . isLogRemoteMessagesEnabled ( ) ) { m_Logging . debug ( "New message of size %d for socket %s" , messageSize , m_Socket . getRemoteSocketAddress ( ) ) ; } messageBuffer = new byte [ messageSize ] ; int bytesRemaining = messageSize ; while ( bytesRemaining > 0 ) { final int bytesRead = m_InputStream . read ( messageBuffer , messageSize - bytesRemaining , bytesRemaining ) ; if ( bytesRead == - 1 ) { m_Logging . error ( "Socket %s closed while reading message, will stop reading from it" , m_Socket . getRemoteSocketAddress ( ) ) ; return null ; } m_AllBytesReceived += bytesRead ; m_Channel . setBytesReceived ( m_AllBytesReceived ) ; bytesRemaining -= bytesRead ; } } catch ( final IOException e ) { m_Logging . error ( e , "Failed to read message from the input stream for socket %s" , m_Socket . getRemoteSocketAddress ( ) ) ; return null ; } return messageBuffer ; }
Read a single {@link TerraHarvestMessage} from the input stream with an octet count of the message size before
 the message.
Read a single { @link TerraHarvestMessage } from the input stream with an octet count of the message size before the message .
// first read size of message coming in // socket has been closed, just return so the thread can exit // reached EOF // now read in message // reached EOF