Groovy 确定字节数组编码
Groovy determine byte array encoding
在 Groovy/Grails?
中有一些方法可以确定字节数组内的内容编码
我只有文件内容存储在数据库中的 blob 中,groovy 端存储为:
byte[] fileData
有一些方法,但它们更像是解决方法。您可以将其转换为字符串,但其构造函数仍需要第二个参数,即编码。字符串构造函数不是 "detect",而是 "use" 传递的编码。
你可以尝试一些编码检测算法,比如mozilla's or jchardet。
This answer 很好地总结了为什么检测字节数组的编码是错误的:
You cannot determine the encoding of a arbitrary byte stream. This is the nature of encodings. A encoding means a mapping between a byte value and its representation. So every encoding "could" be the right.
在 Groovy/Grails?
中有一些方法可以确定字节数组内的内容编码
我只有文件内容存储在数据库中的 blob 中,groovy 端存储为:
byte[] fileData
有一些方法,但它们更像是解决方法。您可以将其转换为字符串,但其构造函数仍需要第二个参数,即编码。字符串构造函数不是 "detect",而是 "use" 传递的编码。
你可以尝试一些编码检测算法,比如mozilla's or jchardet。
This answer 很好地总结了为什么检测字节数组的编码是错误的:
You cannot determine the encoding of a arbitrary byte stream. This is the nature of encodings. A encoding means a mapping between a byte value and its representation. So every encoding "could" be the right.