From 36a07e195f04891673856d31f720ae7aa19b1cea Mon Sep 17 00:00:00 2001 From: Jan Blom Date: Wed, 1 May 2024 16:25:46 +0200 Subject: [PATCH] Add UTF BOM handling code reading of csv's --- .../main/java/org/ohdsi/utilities/files/ReadTextFile.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rabbit-core/src/main/java/org/ohdsi/utilities/files/ReadTextFile.java b/rabbit-core/src/main/java/org/ohdsi/utilities/files/ReadTextFile.java index 5dbcce40..a04ff771 100644 --- a/rabbit-core/src/main/java/org/ohdsi/utilities/files/ReadTextFile.java +++ b/rabbit-core/src/main/java/org/ohdsi/utilities/files/ReadTextFile.java @@ -17,6 +17,8 @@ ******************************************************************************/ package org.ohdsi.utilities.files; +import org.apache.commons.io.input.BOMInputStream; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -46,11 +48,11 @@ public ReadTextFile(InputStream inputStream) { public ReadTextFile(String filename) { this.filename = filename; try { - FileInputStream inputStream = new FileInputStream(filename); + InputStream inputStream = BOMInputStream.builder().setInputStream(new FileInputStream(filename)).get(); bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); } catch (FileNotFoundException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { + } catch (IOException e) { System.err.println("Computer does not support UTF-8 encoding"); e.printStackTrace(); }