如何从字节数组中提取文件扩展名
我在数据库中有字节数组。
如何从Java中的字节数组中提取文件扩展名(MIME /类型)?
回答:
如果这是为了存储上载的文件:
- 为文件扩展名创建一列
- 为浏览器发送的mime类型创建一列
如果您没有原始文件,而只有字节,那么您有两种不错的解决方案。
如果能够使用库,请查看使用mime-util检查字节:
http://technopaper.blogspot.com/2009/03/identifying-mime-using-mime-
util.html
如果必须构建自己的字节检测器,则以下是许多最流行的起始字节:
"BC" => bitcode,"BM" => bitmap,
"BZ" => bzip,
"MZ" => exe,
"SIMPLE"=> fits,
"GIF8" => gif,
"GKSM" => gks,
[0x01,0xDA].pack('c*') => iris_rgb,
[0xF1,0x00,0x40,0xBB].pack('c*') => itc,
[0xFF,0xD8].pack('c*') => jpeg,
"IIN1" => niff,
"MThd" => midi,
"%PDF" => pdf,
"VIEW" => pm,
[0x89].pack('c*') + "PNG" => png,
"%!" => postscript,
"Y" + [0xA6].pack('c*') + "j" + [0x95].pack('c*') => sun_rasterfile,
"MM*" + [0x00].pack('c*') => tiff,
"II*" + [0x00].pack('c*') => tiff,
"gimp xcf" => gimp_xcf,
"#FIG" => xfig,
"/* XPM */" => xpm,
[0x23,0x21].pack('c*') => shebang,
[0x1F,0x9D].pack('c*') => compress,
[0x1F,0x8B].pack('c*') => gzip,
"PK" + [0x03,0x04].pack('c*') => pkzip,
"MZ" => dos_os2_windows_executable,
".ELF" => unix_elf,
[0x99,0x00].pack('c*') => pgp_public_ring,
[0x95,0x01].pack('c*') => pgp_security_ring,
[0x95,0x00].pack('c*') => pgp_security_ring,
[0xA6,0x00].pack('c*') => pgp_encrypted_data,
[0xD0,0xCF,0x11,0xE0].pack('c*') => docfile
以上是 如何从字节数组中提取文件扩展名 的全部内容, 来源链接: utcz.com/qa/411008.html