How to change character encoding for a file using the java api.
3 answers
Text encoding isn't handled by source control. It's however the client is set to interpret the file. For Eclipse clients, there are preferences for the encoding that users can set for each type of file. Eclipse can also set the encoding per project. So the change you're making in the GUI isn't being shared with source control. If something is being shared, do you mean some other file property? The recorded properties are executable bit, mime type, and line delimiter.
Comments
This sort of disagrees with you https://jazz.net/forum/questions/120592/contents-are-not-readable-after-programmatically-delivering-files-to-stream
The javadoc for IFileContentManager#storeContent() doesn't state that it stores the encoding. It uses the encoding to perform validation/translation of line endings.
FYI, you can provide a comment to answer instead of responding to an answer with another answer. This helps categorize responses for other users to quickly identify responses that are answers.
To change the encoding I had to to read the file and restore it using
IFileContent content = file.getContent();
IFileContent newcontent = contentManager.storeContent(content.getCharacterEncoding(),content.getLineDelimiter(),
new VersionedContentManagerByteArrayInputStreamPovider(FileUtils.readFileToByteArray(tmpfile)),null, MONITOR);
// Set content to orginal file content
file = (IFileItem) file.getWorkingCopy();
file.setContent(newcontent);
IFileContent content = file.getContent();
IFileContent newcontent = contentManager.storeContent(content.getCharacterEncoding(),content.getLineDelimiter(),
new VersionedContentManagerByteArrayInputStreamPovider(FileUtils.readFileToByteArray(tmpfile)),null, MONITOR);
// Set content to orginal file content
file = (IFileItem) file.getWorkingCopy();
file.setContent(newcontent);