aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-11-10 16:10:57 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-11-10 16:10:57 +1300
commitd1f6d1ab58e82c7854cb569554f7626be10f7baf (patch)
treef430345b55f3cdcdf074cf4ab90d01fea55fdcab /src
parent84b7b8c28d0a8a19fc1283dd4d3509c0295d8c3d (diff)
downloadtraccar-server-d1f6d1ab58e82c7854cb569554f7626be10f7baf.tar.gz
traccar-server-d1f6d1ab58e82c7854cb569554f7626be10f7baf.tar.bz2
traccar-server-d1f6d1ab58e82c7854cb569554f7626be10f7baf.zip
Fix some FindBugs issues
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/helper/Log.java15
-rw-r--r--src/org/traccar/sms/HttpSmsClient.java3
2 files changed, 12 insertions, 6 deletions
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index a26da6b30..9519a33f1 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -19,11 +19,13 @@ import org.traccar.Config;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.ConsoleHandler;
@@ -59,11 +61,14 @@ public final class Log {
if (writer != null && !suffix.equals(this.suffix)) {
writer.close();
writer = null;
- new File(name).renameTo(new File(name + "." + this.suffix));
+ if (!new File(name).renameTo(new File(name + "." + this.suffix))) {
+ throw new RuntimeException("Log file renaiming failed");
+ }
}
if (writer == null) {
this.suffix = suffix;
- writer = new BufferedWriter(new FileWriter(name, true));
+ writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(name, true), StandardCharsets.UTF_8));
}
writer.write(getFormatter().format(record));
writer.flush();
@@ -74,7 +79,7 @@ public final class Log {
}
@Override
- public void flush() {
+ public synchronized void flush() {
if (writer != null) {
try {
writer.flush();
@@ -85,7 +90,7 @@ public final class Log {
}
@Override
- public void close() throws SecurityException {
+ public synchronized void close() throws SecurityException {
if (writer != null) {
try {
writer.close();
diff --git a/src/org/traccar/sms/HttpSmsClient.java b/src/org/traccar/sms/HttpSmsClient.java
index 3f7bc3c85..994e2db4e 100644
--- a/src/org/traccar/sms/HttpSmsClient.java
+++ b/src/org/traccar/sms/HttpSmsClient.java
@@ -49,7 +49,8 @@ public class HttpSmsClient implements SmsManager {
if (authorization == null) {
String user = Context.getConfig().getString("sms.http.user");
String password = Context.getConfig().getString("sms.http.password");
- authorization = "Basic " + DataConverter.printBase64((user + ":" + password).getBytes());
+ authorization = "Basic "
+ + DataConverter.printBase64((user + ":" + password).getBytes(StandardCharsets.UTF_8));
}
template = Context.getConfig().getString("sms.http.template").trim();
if (template.charAt(0) == '{' || template.charAt(0) == '[') {