I want to get file type of the file on provided URL. If is it a GIF file, I need to know that.
Example URL : https://media3.giphy.com/avatars/100soft/WahNEDdlGjRZ.gif (it may not always include a file extension)
I'm working on Android
I want to get file type of the file on provided URL. If is it a GIF file, I need to know that.
Example URL : https://media3.giphy.com/avatars/100soft/WahNEDdlGjRZ.gif (it may not always include a file extension)
I'm working on Android
Get the InputStream from the URL: InputStream from a URL
Most solutions will have you reading the whole stream, but that's not completely necessary because you only need to check the first three bytes.
Convert it to a 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