From d9d1dba18452e55a0801284570411bc4b1be279d Mon Sep 17 00:00:00 2001 From: tknall Date: Mon, 14 Dec 2009 17:57:59 +0000 Subject: Reading templates line by line again git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@517 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/cfg/SettingsReader.java | 6 +++- .../knowcenter/wag/egov/egiz/tools/FileHelper.java | 33 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java index eabff4d..676ef5c 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java @@ -47,6 +47,7 @@ import at.knowcenter.wag.egov.egiz.PdfAS; import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.pdf.Utils; +import at.knowcenter.wag.egov.egiz.tools.FileHelper; /** * The SettingsReader reads the settings.txt file. The @@ -621,7 +622,8 @@ public class SettingsReader implements Serializable * @return null in case of error */ public String readInternalResourceAsString(String relativePath) { - return readAsString(getInternalResource(relativePath)); +// return readAsString(getInternalResource(relativePath)); + return FileHelper.readFromInputStream(getInternalResource(relativePath)); } /** @@ -651,6 +653,7 @@ public class SettingsReader implements Serializable * @param is * @return null in case of error */ + /* public String readAsString(InputStream is) { if (is == null) return null; try { @@ -660,6 +663,7 @@ public class SettingsReader implements Serializable } return null; } + */ // /** // * This method checks the application context. diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java index e72e52e..eb5e8c7 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java @@ -21,11 +21,13 @@ package at.knowcenter.wag.egov.egiz.tools; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.IOException; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import org.apache.log4j.Logger; @@ -52,7 +54,7 @@ public class FileHelper { String file_string = null; logger_.trace("Looking for file: " + fileName); try { - BufferedReader reader = new BufferedReader(new FileReader(fileName)); + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8")); logger_.trace("Reading file: " + fileName); String line = null; file_string = ""; @@ -69,6 +71,31 @@ public class FileHelper { return file_string; } + /** + * This method reads a file by reading line by line. + * + * @param fileName the file to be read + * @return the content string of the file + */ + public static String readFromInputStream(InputStream inputStream) { + String file_string = null; + if (inputStream == null) { + return null; + } + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + String line = null; + file_string = ""; + while ((line = reader.readLine()) != null) { + file_string += line; + } + reader.close(); + } catch (IOException e) { + logger_.debug("Error reading inputstream."); + } + return file_string; + } + /** * This method writes a file line by line. * -- cgit v1.2.3