I have an array of bytes. Irrelevant: I use the iText library and somehow parsing fails when trying to extract text from that array. I have traced the problem to be related to a corrupt PDF document (the bytes). So, I would like to edit the array of bytes before feeding it to the library.
byte[] bytesArray;
String x = new String(bytesArray);
x = x.replace("foo", "bar");
library.parse(x.getBytes());
How is this different from the following?
library.parse(bytesArray);
Thanks.
Use:
Explanation:
The constructor
new String(byte[])and the methodString.getBytes()use the “platform default character encoding” to convert between characters and bytes. Not all byte sequences can be mapped to characters in all character encodings. The constructed String will contain the unicode replacement character \uFFFD where unmappable sequences were found. The solution is to use a character encoding where every byte sequence is legal. One such encoding is ISO-8859-1. (UTF-8 for example would not work.)