static void receiveBytes ( final Socket sock, final int expected ) throws IOException {
        @SuppressWarnings ( "resource" )
        InputStream in = sock.getInputStream();

        int toExpect = expected;

        char firstChar = 'A';

        int available = in.available();
        if ( available == 0 && expected != 0 ) {
            // this may happen, and it's ok.
            int r = in.read();
            assertEquals("Available returned 0, so we tried to read the first byte (which should be 65=='A')", 'A', r);

            // as we have already read one byte, we now expect one byte less
            toExpect--;

            available = in.available();

            firstChar = 'B';
        }
        assertEquals(toExpect, available);
        byte[] buf = new byte[expected];
        int numRead = in.read(buf);
        assertEquals(toExpect, numRead);

        for ( int i = 0; i < numRead; i++ ) {
            assertEquals(firstChar + i, buf[ i ] & 0xFF);
        }

        assertEquals(0, in.available());
    }