    @Test
    public void testReadFromInputStreamWithExtraData() throws IOException {

        // tests that this can extract the JSON even if more data follows in the stream
        ApiDeserializer ad = new ApiDeserializer();

        String nameAndJson = EchoRequest.class.getName() + "={\"echoMessage\":\"msg\"}";
        String extra = "This is some extra data";
        String nameAndJsonPlusExtra = nameAndJson + extra;

        ByteArrayInputStream in = new UncloseableByteArrayInputStream(nameAndJsonPlusExtra.getBytes());

        BasicMessageWithExtraData<AbstractMessage> map = ad.deserialize(in);
        AbstractMessage request = map.getBasicMessage();
        Assert.assertTrue(request instanceof EchoRequest);
        EchoRequest echoRequest = (EchoRequest) request;
        Assert.assertEquals("msg", echoRequest.getEchoMessage());

        // now make sure the stream still has our extra data that we can read now
        BinaryData leftover = map.getBinaryData();
        byte[] leftoverByteArray = new byte[leftover.available()];
        leftover.read(leftoverByteArray);

        String totalRemaining = new String(leftoverByteArray, "UTF-8");
        Assert.assertEquals(extra.length(), totalRemaining.length());
        Assert.assertEquals(extra, totalRemaining);

        // as a quick test, show that an exception results if we give bogus data in the input stream
        in = new UncloseableByteArrayInputStream("this is not valid data".getBytes());
        try {
            ad.deserialize(in);
            Assert.fail("Should have thrown an exception - the stream had invalid data");
        } catch (Exception expected) {
        }
    }