Reputation: 3
There are ways to determine content encoding inside byte array in Groovy/Grails?
I has only file content stored inside database in blob and groovy side is stored as:
byte[] fileData
Upvotes: 0
Views: 624
Reputation: 14539
There are some ways, but they are more like workarounds. You could transform it into a String, but its constructors still need a second parameter which is the encoding. String constructors don't "detect", but rather "use" the passed encoding.
You could try some encoding detecting algorithms, like mozilla's or jchardet.
This answer sums nicely why detecting encoding from a byte array is wrong:
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.
Upvotes: 1