I have an application which listens to the external feed on hourly basis and receives the feed JSON which is a chunked transfer encoding stream, the listener to the feed write the chunk to the file, after the whole stream is completed another thread parses the file and extracts the data. But now while writing the file the data is written in binary format even though I have specified the charset while writing.
public void writeToFile(InputStream in){
File feedFile = new File("/tmp/feed.json");
try {
FileUtils.touch(feedFile);
StringWriter writer = new StringWriter();
IOUtils.copy(in, writer, StandardCharsets.UTF_8);
FileUtils.write(feedFile, writer.toString(), StandardCharsets.UTF_8,true);
} catch (IOException e) {
logger.error(Constants.FAILED_TO_WRITE_FEED_INTO_FILE,e);
}
}
This code works fine on windows and linux box, but while inside docker container its written in binary format.
Docker container used Centos7