Permalink
Browse files

some cleaning of Mary4To5VoiceConverter

hopefully fixes #61; this also restores the convention set forth in v4.1.0 that config files must use CRLF (Windows) EOL encoding

finally some trivial edits favoring Apache Commons
  • Loading branch information...
1 parent 6ff7d4a commit a0278685333d1fc7635c7a2121c773caf8f74cc3 @psibre psibre committed Jul 30, 2012
Showing with 13 additions and 12 deletions.
  1. +13 −12 marytts-builder/src/main/java/marytts/tools/upgrade/Mary4To5VoiceConverter.java
@@ -17,13 +17,13 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
@@ -38,10 +38,10 @@
import marytts.util.MaryUtils;
import marytts.util.dom.DomUtils;
import marytts.util.io.FileUtils;
-import marytts.util.string.StringUtils;
public class Mary4To5VoiceConverter {
+ private static final String EOL = IOUtils.LINE_SEPARATOR_WINDOWS;
/**
* The list of property suffixes which can read from a resource file.
@@ -99,7 +99,7 @@
private VoiceComponentDescription voiceDescription;
private File mary4Zip;
private Properties config;
- private String originalConfig;
+ private List<String> originalConfig;
private File extractedDir;
private File compileDir;
@@ -215,18 +215,17 @@ protected void saveConfigToStream(OutputStream out) throws IOException {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
StringBuilder comments = new StringBuilder();
try {
- String[] lines = StringUtils.toStringArray(originalConfig);
- for (String line : lines) {
+ for (String line : originalConfig) {
if (isEmpty(line) || isComment(line)) {
- comments.append(line).append('\n');
+ comments.append(line).append(EOL);
continue;
}
String key = new StringTokenizer(line.trim()).nextToken();
if (config.containsKey(key)) {
pw.print(comments.toString());
- pw.print(key + " = " + config.getProperty(key) + "\r\n");
+ pw.print(key + " = " + config.getProperty(key) + EOL);
if (key.equals("name")) {
- pw.print("locale = " + config.getProperty("locale") + "\r\n");
+ pw.print("locale = " + config.getProperty("locale") + EOL);
}
}
comments = new StringBuilder();
@@ -314,15 +313,17 @@ private File findConfigFile() throws IOException {
}
protected void loadConfig(File configFile) throws IOException {
- loadConfigFromStream(new BufferedInputStream(new FileInputStream(configFile)));
+ FileInputStream configStream = new FileInputStream(configFile);
+ InputStream bufferedConfigStream = IOUtils.toBufferedInputStream(configStream);
+ loadConfigFromStream(bufferedConfigStream);
}
protected void loadConfigFromStream(InputStream in) throws IOException {
config = new Properties();
try {
- originalConfig = FileUtils.getStreamAsString(in, "UTF-8");
- ByteArrayInputStream bain = new ByteArrayInputStream(originalConfig.getBytes());
- config.load(bain);
+ byte[] byteArray = IOUtils.toByteArray(in);
+ config.load(new ByteArrayInputStream(byteArray));
+ originalConfig = IOUtils.readLines(new ByteArrayInputStream(byteArray), "UTF-8");
} finally {
in.close();
}

0 comments on commit a027868

Please sign in to comment.