Use InputStream#mark() when detecting mime types from streams