Burak Taban Burak Taban - 1 year ago 89
Android Question

Android Check if is it GIF on the URL

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)

Answer Source

Get the InputStream from the URL to a byte[]

InputStream from a URL

Convert InputStream to byte array in Java

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.

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")


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download