cancel
Showing results for 
Search instead for 
Did you mean: 

Encoding Problem

mangar
Star Contributor
Star Contributor
I have a simple text file in Alfresco that has this content in it:  “Generic Table Template”

I have this code:
       ContentReader reader = contentService.getReader(node, ContentModel.PROP_CONTENT);
       if(reader != null) {
          System.out.println("Writing File:"+filename);
          System.out.println("Default encoding:"+reader.getEncoding());
         File f = new File(filename);
         reader.getContent(f);
       }

The default encoding is showing up correctly as UTF-8

however, when I look at the written file I see this:   ���Generic Table Template���

Any Ideas?
5 REPLIES 5

mrogers
Star Contributor
Star Contributor
you don't appear to have posted any relevant code.

mangar
Star Contributor
Star Contributor
I am confused.  I posted the entire method.  I get a ContentReader from the content service, and then according to the API, the line 
reader.getContent(f);

should write the content to a file.  Which it does, it just messes up the encoding somehow, even though reader.getEncoding() properly returns UTF-8

mrogers
Star Contributor
Star Contributor
Smiley Surprisedops:

I suspect its a bug and its writing in O.S. default encoding not UTF-8.   However I've checked the code and can't see a problem.

mrogers
Star Contributor
Star Contributor
How are you "looking" at that file?    With these sorts of problems I find it useful to use a "hex dump" utility so we can actually see the bytes that have been written.

mangar
Star Contributor
Star Contributor
YES!  Default OS file encoding is the problem. (almost)  It was a JVM problem. I simply added -Dfile.encoding=UTF-8 to the startup script and the code above works perfectly.

Thank you all