private ResultMessage handleResponse() throws IOException
    {
        DataInputStream input;
        byte[] buffer;
        MsgHeaderResponse_PI responseHeaderPI;
        ProtocolToken pt = null;
        RError_PI errMsg = null;
        ProtocolToken bodyToken = null;

        input = new DataInputStream(connection.getInputStream());

        //1. Read response bytes
        int responseHeaderSize = RodsUtil.parseInt(RodsUtil.readBytes(4, input));
        if ( debug )
        {
            LOG.debug("Read response header size: " + responseHeaderSize);
        }
        if (responseHeaderSize < 0 || responseHeaderSize > MAX_HEADER_SIZE)
        {
            LOG.info("Unexpected header size " + responseHeaderSize + " is this even irods?");
            throw new IOException("Unexpected header size " + responseHeaderSize);
        }
        
        //2. Read response header
        buffer = RodsUtil.readBytes(responseHeaderSize, input);

        pt = ProtocolToken.parseToken(new String(buffer));
        responseHeaderPI = new MsgHeaderResponse_PI(pt);
        if ( debug )
        {
            LOG.debug("Read response header " + responseHeaderPI);
        }


        //5. parse response body
        if ( responseHeaderPI.getMsgLen() > 0 )
        {
            buffer = RodsUtil.readBytes(responseHeaderPI.getMsgLen(), input);

            // get token and verify/ set w/ command
            bodyToken = ProtocolToken.parseToken(new String(buffer));
            if ( debug )
            {
                LOG.debug("Read message token: " + bodyToken);
            }
        }

        //6. parse error message
        if ( responseHeaderPI.getErrorLen() > 0 )
        {
            buffer = RodsUtil.readBytes(responseHeaderPI.getErrorLen(), input);
            pt = ProtocolToken.parseToken(new String(buffer));
            errMsg = new RError_PI(pt);
            if ( debug )
            {
                LOG.debug("Read error token: " + errMsg);
            }

        }

        //7. wrap input stream
        if ( responseHeaderPI.getBsLen() > 0 )
        {
            activeInput =
                    new RodsInputStream(input, responseHeaderPI.getBsLen());
        }
        else
        {
            activeInput = null;
        }
        return new ResultMessage(responseHeaderPI, bodyToken, errMsg,
                activeInput);
    }