Skip to content

Commit 2cf9d72

Browse files
committed
Use stream and let stax figure out encoding
1 parent 2e351ee commit 2cf9d72

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/test/java/org/codehaus/plexus/components/secdispatcher/internal/DefaultSecDispatcherTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
package org.codehaus.plexus.components.secdispatcher.internal;
1515

16-
import java.io.FileWriter;
16+
import java.io.OutputStream;
1717
import java.nio.charset.StandardCharsets;
18+
import java.nio.file.Files;
19+
import java.nio.file.Paths;
1820
import java.util.Base64;
1921
import java.util.Map;
2022
import java.util.Set;
@@ -49,9 +51,8 @@ private void saveSec(String masterSource) throws Exception {
4951
sec.setMasterSource(masterSource);
5052
sec.setMasterCipher(AESGCMNoPadding.CIPHER_ALG);
5153

52-
try (FileWriter fw = new FileWriter("./target/sec.xml")) {
53-
new SecurityConfigurationStaxWriter().write(fw, sec);
54-
fw.flush();
54+
try (OutputStream fos = Files.newOutputStream(Paths.get("./target/sec.xml"))) {
55+
new SecurityConfigurationStaxWriter().write(fos, sec);
5556
}
5657
System.setProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_CONFIGURATION_LOCATION, "./target/sec.xml");
5758
}

src/test/java/org/codehaus/plexus/components/secdispatcher/internal/SecUtilTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
package org.codehaus.plexus.components.secdispatcher.internal;
1515

16-
import java.io.FileWriter;
16+
import java.io.OutputStream;
17+
import java.nio.file.Files;
18+
import java.nio.file.Paths;
1719
import java.util.Map;
1820

1921
import org.codehaus.plexus.components.secdispatcher.model.Config;
@@ -54,9 +56,8 @@ private void saveSec(String masterSource) throws Exception {
5456

5557
sec.addConfiguration(conf);
5658

57-
try (FileWriter fw = new FileWriter("./target/sec1.xml")) {
58-
new SecurityConfigurationStaxWriter().write(fw, sec);
59-
fw.flush();
59+
try (OutputStream fos = Files.newOutputStream(Paths.get("./target/sec1.xml"))) {
60+
new SecurityConfigurationStaxWriter().write(fos, sec);
6061
}
6162
}
6263

@@ -65,9 +66,8 @@ public void prepare() throws Exception {
6566
System.setProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_CONFIGURATION_LOCATION, "./target/sec.xml");
6667
SettingsSecurity sec = new SettingsSecurity();
6768
sec.setRelocation("./target/sec1.xml");
68-
try (FileWriter fw = new FileWriter("./target/sec.xml")) {
69-
new SecurityConfigurationStaxWriter().write(fw, sec);
70-
fw.flush();
69+
try (OutputStream fos = Files.newOutputStream(Paths.get("./target/sec.xml"))) {
70+
new SecurityConfigurationStaxWriter().write(fos, sec);
7171
}
7272
saveSec("magic:mighty");
7373
}

0 commit comments

Comments
 (0)