public MediaType detect(InputStream input, Metadata metadata) {
        // Look for a type hint in the input metadata
        String hint = metadata.get(Metadata.CONTENT_TYPE);
        if (hint != null) {
            MediaType type = MediaType.parse(hint);
            if (type != null) {
                return type;
            }
        }
        return MediaType.OCTET_STREAM;
    }
@Test
    public void testDetect() {
        assertDetect(MediaType.TEXT_PLAIN, "text/plain");
        assertDetect(MediaType.TEXT_PLAIN, "TEXT/PLAIN");
        assertDetect(MediaType.TEXT_PLAIN, " text/\tplain\n");
        assertDetect(TEXT_PLAIN_A_EQ_B, "text/plain; a=b");
        assertDetect(TEXT_PLAIN_A_EQ_B, "\ttext/plain; a=b\n");

        assertDetect(MediaType.OCTET_STREAM, "text\\plain");

        // test also the zero input cases
        assertDetect(MediaType.OCTET_STREAM, "");
        assertDetect(MediaType.OCTET_STREAM, null);
        try {
            assertEquals(MediaType.OCTET_STREAM, detector.detect(null, new Metadata()));
        } catch (IOException e) {
            fail("TypeDetector should never throw an IOException");
        }
    }