My task is to export VCF (stored in a string file.getValue()) In windows I need 1251 charset but string is in UTF-8. I’ve tried:
String utf8String;
String ansiString = file.getValue();//in case try fails at least utf8 will be as out
try {
utf8String = new String(file.getValue().getBytes(), "UTF-8");
ansiString = new String(utf8String.getBytes("UTF-8"), "windows-1251");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Error while reEncoding", e);
}
exportDisplay.show(new ByteArrayDataProvider(ansiString.getBytes()),
file.getKey(), ExportFormat.OCTET_STREAM);
But for examle ‘file’ contained “Ф И О” I get “В¤ Р пїЅ Р С›” in the resulting file. How do I correctly triger saving file in win-1251 if original string(file.getValue() which is file content) was in utf-8?
PS: in non-windows platforms the following code works and perfectly saves file in utf8
exportDisplay.show(new ByteArrayDataProvider(file.getValue().getBytes()
), file.getKey(), ExportFormat.OCTET_STREAM);
but I need to save file in cp1251