Skip to content

Commit

Permalink
refactor: Use constant StandardCharsets.UTF_8 and StandardCharsets.UT…
Browse files Browse the repository at this point in the history
…F_16 instead of literal
  • Loading branch information
sgcr committed Nov 2, 2024
1 parent f9621b0 commit 6890b81
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/java/core/gui/language/LanguageTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void save() {
BufferedWriter bw = null;

try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destinationPath.getPath()), "UTF-8"));
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destinationPath.getPath()), StandardCharsets.UTF_8));

// Loop over table and put into properties
for (String key : this.keys) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/core/net/test/ConnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

import javax.swing.JTextArea;
Expand Down Expand Up @@ -79,7 +80,7 @@ private static void testHtStartUrl(JTextArea log) {
httpurlconnection.setRequestMethod("GET");
httpurlconnection.connect();
InputStream is = httpurlconnection.getInputStream();
final BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
final BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
String line = null;
boolean found = false;
Expand Down Expand Up @@ -119,7 +120,7 @@ private static void testNormalUrl(JTextArea log) {
httpurlconnection.setRequestMethod("GET");
httpurlconnection.connect();
InputStream is = httpurlconnection.getInputStream();
final BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
final BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
String line = null;
boolean found = false;
while ((line = br.readLine()) != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/core/util/UTF8Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class UTF8Control extends Control {
if (stream != null) {
try {
// Only this line is changed to make it to read properties files as UTF-8.
bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
bundle = new PropertyResourceBundle(new InputStreamReader(stream, StandardCharsets.UTF_8));
} finally {
stream.close();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/core/util/UnicodeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

/**
* Simple converter to convert an language file for the use in HO. Input must be
Expand All @@ -31,7 +32,7 @@ public static void main(String[] args) throws Exception {
System.out.println("Can't access input file '" + input + "'!");
return;
}
r = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-16"));
r = new BufferedReader(new InputStreamReader(new FileInputStream(input), StandardCharsets.UTF_16));
String line;
int linecount = 0;
while ((line = r.readLine()) != null) {
Expand Down

0 comments on commit 6890b81

Please sign in to comment.