Write file ansi file in groovy

Jens Kisters __SeibertSolutions
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2019

Hello everyone,

i have trouble writing an ANSI file from groovy,

i get a file that is recognized by notepad++ as "Windows-1252" but the special characters don't display properly.

ansi.PNG

import java.io.FileWriter
import java.io.BufferedWriter
import java.io.InputStream
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets


String fullPath = "/tmp/jamesTempFiles/ansi.txt"

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fullPath), "Cp1252"))
//doesn't work either when i use the following line instead
//BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fullPath), "windows-1252"))
String input = "test\r\näüöß"

writer.write(input)
//doesn't work either when i use the following line instead
//writer.write(new String(input.getBytes(Charset.forName("utf-8"))))
writer.close()

 Any Ideas?

 

Thanks in Advance

Jens

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 11, 2019

Hi Jens,

I see that you are trying to export a text file but that the output appears to be in an different file encoding than expected.

I suspect that the file getting created here is subject to the JVM's character encoding settings.  While we recommend Jira server installs use the UTF-8 encoding, this doesn't always happen out of the box.  And if your Jira server is running on a Windows machine, I have see that 'windows-1255' encoding tends to get used in Windows based JVMs by default unless manually specified.   To that end, I would recommend trying to follow the steps in the KB JIRA Application internationalisation and encoding troubleshooting. Specifically from that KB:

Start JIRA with the parameters -Dfile.encoding=utf-8 and -Dsun.jnu.encoding=UTF-8. See Setting properties and options on startup.

Adding those two JVM parameters should make sure that Jira starts up with the correct file encoding and JVM encoding.  Perhaps the subsequent functions of groovy/scriptrunner are dependent upon the JVM's encoding settings at the time of execution.  If my hunch is correct then setting these options and restarting Jira could help here.

Try this and let me know the results.

Andy

Suggest an answer

Log in or Sign up to answer