### Question:
MimeTypeInputStream extends FilterInputStream { public MimeType getMimeType() { return mimeType; } MimeTypeInputStream(final InputStream stream); MimeType getMimeType();  }### Answer:
@Test void checkForZipMimeTypeSupport() throws IOException { final byte[] rawData = {0x50, 0x4b, 0x11, 0x3a, 0x4e}; final InputStream rawInputStream = new ByteArrayInputStream(rawData); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertEquals(MimeType.ZIP, mimeType); Assertions.assertEquals(0x50, inputStream.read()); Assertions.assertEquals(0x4b, inputStream.read()); Assertions.assertEquals(0x11, inputStream.read()); }
@Test void checkForNotSupportedMimeTypeSupport() throws IOException { final byte[] rawData = {0x51, 0x2b, 0x11, 0x3a, 0x4e}; final InputStream rawInputStream = new ByteArrayInputStream(rawData); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertNull(mimeType); Assertions.assertEquals(0x51, inputStream.read()); Assertions.assertEquals(0x2b, inputStream.read()); Assertions.assertEquals(0x11, inputStream.read()); }
@Test void checkEmptyData() throws IOException { final byte[] rawData = new byte[0]; final InputStream rawInputStream = new ByteArrayInputStream(rawData); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertNull(mimeType); Assertions.assertEquals(-1, inputStream.read()); }
@Test void checkForZipFile() throws IOException { final InputStream rawInputStream = getClass().getResourceAsStream("data.zip"); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertEquals(MimeType.ZIP, mimeType); final ZipInputStream zipInputStream = new ZipInputStream(inputStream); final ZipEntry entry = zipInputStream.getNextEntry(); Assertions.assertNotNull(entry); Assertions.assertEquals("data.txt", entry.getName()); }
@Test void checkForGZipFile() throws IOException { final InputStream rawInputStream = getClass().getResourceAsStream("data.gz"); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertEquals(MimeType.GZIP, mimeType); }
@Test void checkForTarGzFile() throws IOException { final InputStream rawInputStream = getClass().getResourceAsStream("data.tar.gz"); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertEquals(MimeType.GZIP, mimeType); }
@Test void checkForUnsupportedFile() throws IOException { final InputStream rawInputStream = getClass().getResourceAsStream("data.txt"); final MimeTypeInputStream inputStream = new MimeTypeInputStream(rawInputStream); final MimeType mimeType = inputStream.getMimeType(); Assertions.assertNull(mimeType); Assertions.assertEquals(0x53, inputStream.read()); Assertions.assertEquals(0x6f, inputStream.read()); }