检查 URL InputStream 是否包含 GIF
Check URL InputStream contains a GIF
我想获取提供的文件的文件类型 URL。如果是GIF文件,我需要知道。
示例 URL:https://media3.giphy.com/avatars/100soft/WahNEDdlGjRZ.gif(它可能并不总是包含文件扩展名)
我正在研究 Android
从 URL 获取 InputStream:InputStream from a URL
大多数解决方案会让您读取整个流,但这并不是完全必要的,因为您只需要检查前三个字节。
将其转换为 byte[]
:Convert InputStream to byte array in Java
All GIF files must start with a header block. The header takes up the first six bytes of the file. These bytes should all correspond to ASCII character codes. The first three bytes are called the signature. These should always be "GIF" (ie 47="G", 49="I", 46="F")
http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html
我想获取提供的文件的文件类型 URL。如果是GIF文件,我需要知道。
示例 URL:https://media3.giphy.com/avatars/100soft/WahNEDdlGjRZ.gif(它可能并不总是包含文件扩展名)
我正在研究 Android
从 URL 获取 InputStream:InputStream from a URL
大多数解决方案会让您读取整个流,但这并不是完全必要的,因为您只需要检查前三个字节。
将其转换为 byte[]
:Convert InputStream to byte array in Java
All GIF files must start with a header block. The header takes up the first six bytes of the file. These bytes should all correspond to ASCII character codes. The first three bytes are called the signature. These should always be "GIF" (ie 47="G", 49="I", 46="F")
http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html