Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to change character encoding for a file using the java api.

I have the file         IFileItem file = (IFileItem) filePath.getFullState();
I can change a few attributes, but I can find nothing about changing the encoding.

I can change the encoding using the gui, but I have not found a way to change it using the java api.

0 votes



3 answers

Permanent link
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.

0 votes

Comments

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.


Permanent link
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);



0 votes


Permanent link
           IFileContent newcontent = contentManager.storeContent(<new encoding goes here>,content.getLineDelimiter(),
                    new VersionedContentManagerByteArrayInputStreamPovider(FileUtils.readFileToByteArray(tmpfile)),null, MONITOR); 

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jul 26 '13, 10:49 a.m.

Question was seen: 6,145 times

Last updated: Jul 29 '13, 8:43 a.m.

Confirmation Cancel Confirm