gpt4 book ai didi

java - 检查 URL 输入流是否包含 GIF

转载 作者:行者123 更新时间:2023-12-01 17:54:55 24 4
gpt4 key购买 nike

我想获取提供的 URL 上的文件的文件类型。如果它是 GIF 文件,我需要知道。

示例网址: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

关于java - 检查 URL 输入流是否包含 GIF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45910447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com