TypeDetector implements Detector { public MediaType detect(InputStream input, Metadata 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; }  MediaType detect(InputStream input, Metadata metadata);  }
@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"); 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"); } }