Skip to content

Commit

Permalink
#21: Fixed encoding problem in translation statistics. ini file is no…
Browse files Browse the repository at this point in the history
…w UTF8
  • Loading branch information
k3b committed Oct 16, 2019
1 parent dc1b913 commit e397e7d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.io.Properties;
import de.k3b.io.collections.SelectedFiles;
import de.k3b.io.collections.SelectedItems;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@
import android.view.Menu;
import android.view.MenuItem;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.Global;
Expand All @@ -49,6 +46,7 @@
import de.k3b.android.widget.Dialogs;
import de.k3b.database.SqlTemplateEngine;
import de.k3b.io.FileUtils;
import de.k3b.io.Properties;

/**
* #70: Handles optional extra context specific detail text that can be displayed in
Expand Down Expand Up @@ -116,11 +114,11 @@ protected Properties loadFromFile() {
File propFile = getPropertiesFile();

if (propFile.exists()) {
Reader br = null;
InputStream br = null;

try {

br = new BufferedReader(new InputStreamReader(new FileInputStream(propFile), "UTF-8"));
br = new FileInputStream(propFile);
properties.load(br);

} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import de.k3b.android.androFotoFinder.Common;
import de.k3b.android.androFotoFinder.GalleryFilterPathState;
Expand All @@ -50,6 +49,7 @@
import de.k3b.io.FileUtils;
import de.k3b.io.GalleryFilterParameter;
import de.k3b.io.IGalleryFilter;
import de.k3b.io.Properties;
import de.k3b.io.StringUtils;
import de.k3b.tagDB.TagProcessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.Properties;

import de.k3b.LibGlobal;
import de.k3b.media.IPhotoProperties;
Expand Down
35 changes: 35 additions & 0 deletions fotolib2/src/main/java/de/k3b/io/Properties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.k3b.io;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class Properties extends java.util.Properties {

private static final String FILE_ENCODING = "UTF-8";

@Override
public synchronized void load(InputStream inputStream) throws IOException {
InputStreamReader in = null;
try {
in = new InputStreamReader(inputStream, FILE_ENCODING);
load(in);
} finally {
FileUtils.close(in, inputStream);
}
}

public void store(OutputStream stream, String comment) throws IOException {
Writer o = null;
try {
o = new BufferedWriter(new OutputStreamWriter(stream, FILE_ENCODING));
store(o, comment);
} finally {
FileUtils.close(o, stream);
}
}
}
2 changes: 1 addition & 1 deletion fotolib2/src/main/java/de/k3b/zip/ZipConfigRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Properties;

import de.k3b.LibGlobal;
import de.k3b.io.DateUtil;
import de.k3b.io.FileUtils;
import de.k3b.io.Properties;
import de.k3b.io.StringUtils;

/** Parameters that define a backup that can be persisted through a properties-file */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import de.k3b.LibGlobal;
import de.k3b.TestUtil;
import de.k3b.io.collections.SelectedFiles;
import de.k3b.media.ExifInterface;
import de.k3b.media.ExifInterfaceEx;
import de.k3b.media.IPhotoProperties;
import de.k3b.media.MediaFormatter.FieldID;
import de.k3b.media.PhotoPropertiesBulkUpdateService;
import de.k3b.media.PhotoPropertiesDTO;
import de.k3b.media.PhotoPropertiesDiffCopy;
import de.k3b.media.PhotoPropertiesFormatter;
import de.k3b.media.MediaFormatter.FieldID;
import de.k3b.transactionlog.TransactionLoggerBase;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -48,6 +46,7 @@
import de.k3b.io.DateUtil;
import de.k3b.io.FileUtils;
import de.k3b.io.ListUtils;
import de.k3b.io.Properties;

/**
* Creates a translation statistics in Markdown-format for the app from
Expand Down Expand Up @@ -247,10 +246,10 @@ private static Document getXml(File file) {

public TranslationStatistics() {
Date fileLimitDate = null;
InputStreamReader inputStream = null;
InputStream inputStream = null;

try {
inputStream = new InputStreamReader(new FileInputStream(iniFile), "UTF-8");
inputStream = new FileInputStream(iniFile);
lastLocales.load(inputStream);

fileLimitDate = getModifyDateProperty("ignore");
Expand Down

0 comments on commit e397e7d

Please sign in to comment.