Skip to content

Commit 64732d3

Browse files
committed
code fixes
1 parent 5abe8c1 commit 64732d3

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

logicaldoc-util/src/main/java/com/logicaldoc/util/config/ContextProperties.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.io.InputStream;
88
import java.net.URL;
99
import java.net.URLDecoder;
10-
import java.nio.charset.Charset;
10+
import java.nio.charset.StandardCharsets;
1111
import java.nio.file.Files;
1212
import java.text.SimpleDateFormat;
1313
import java.util.ArrayList;
@@ -33,6 +33,8 @@
3333
*/
3434
public class ContextProperties extends OrderedProperties {
3535

36+
private static final String UTF_8 = "UTF-8";
37+
3638
private static final String BASE64_PREFIX = "_b64_";
3739

3840
private static final String UNABLE_TO_READ_FROM = "Unable to read from %s";
@@ -112,7 +114,7 @@ public ContextProperties(URL fileUrl) throws IOException {
112114
*/
113115
private void load(URL fileUrl) throws IOException {
114116
try {
115-
file = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8"));
117+
file = new File(URLDecoder.decode(fileUrl.getPath(), UTF_8));
116118
} catch (Exception e) {
117119
throw new IOException(String.format(UNABLE_TO_READ_FROM, file.getPath()), e);
118120
}
@@ -270,7 +272,7 @@ public String getString(String property, String defaultValue) {
270272
String value = getProperty(property, defaultValue);
271273
if (value.startsWith(BASE64_PREFIX))
272274
value = new String(Base64.getDecoder().decode(value.substring(BASE64_PREFIX.length())),
273-
Charset.forName("UTF-8"));
275+
StandardCharsets.UTF_8);
274276
return StrSubstitutor.replaceSystemProperties(value);
275277
}
276278

@@ -334,7 +336,7 @@ public float getFloat(String property, float defaultValue) {
334336
@Override
335337
public synchronized Object setProperty(String key, String value) {
336338
if (value.contains("\n"))
337-
value = BASE64_PREFIX + Base64.getEncoder().encodeToString(value.getBytes(Charset.forName("UTF-8")));
339+
value = BASE64_PREFIX + Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));
338340
return super.setProperty(key, value);
339341
}
340342

logicaldoc-util/src/test/java/com/logicaldoc/util/config/ContextPropertiesTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.Assert.assertEquals;
44

55
import java.io.File;
6-
import java.io.FileNotFoundException;
76
import java.io.FileReader;
87
import java.io.IOException;
98
import java.nio.charset.StandardCharsets;
@@ -37,7 +36,7 @@ public void testWrite() throws IOException {
3736
}
3837

3938
@Test
40-
public void testSetAndGetProperty() throws FileNotFoundException, IOException {
39+
public void testSetAndGetProperty() throws IOException {
4140
File abcFile = new File("target/abc.properties");
4241
ContextProperties contextProperties = new ContextProperties(abcFile);
4342

@@ -57,8 +56,7 @@ public void testSetAndGetProperty() throws FileNotFoundException, IOException {
5756

5857
assertEquals("pippo", contextProperties.getString("propA"));
5958
assertEquals("pippo\npluto\npaperino", contextProperties.getString("propB"));
60-
assertEquals(" Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
61-
contextProperties.getString("propC"));
59+
assertEquals(" Lorem ipsum dolor sit amet, consectetur adipiscing elit.", contextProperties.getString("propC"));
6260
assertEquals("", contextProperties.getString("emptyKey"));
6361

6462
Properties properties = new Properties();
@@ -70,7 +68,7 @@ public void testSetAndGetProperty() throws FileNotFoundException, IOException {
7068

7169
// testing explicit encoding and decoding (Properties class)
7270
assertEquals("pippo", properties.getProperty("propA"));
73-
assertEquals("_b64_"+Base64.getEncoder().encodeToString("""
71+
assertEquals("_b64_" + Base64.getEncoder().encodeToString("""
7472
pippo
7573
pluto
7674
paperino""".getBytes()), properties.getProperty("propB"));

0 commit comments

Comments
 (0)