Skip to content

Commit 08f8deb

Browse files
committed
Fix file writer
1 parent 05f2afd commit 08f8deb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

components/context/src/test/java/datadog/context/SourceFileExtension.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.context;
22

3+
import java.io.BufferedWriter;
4+
import java.io.FileWriter;
35
import java.nio.file.Files;
46
import java.nio.file.Path;
57
import java.nio.file.Paths;
@@ -43,9 +45,9 @@ public void executionFinished(
4345
Matcher matcher = pattern.matcher(fileContent);
4446
StringBuffer result = new StringBuffer();
4547
while (matcher.find()) {
46-
String beg_attributes = matcher.group(1);
48+
String begAttributes = matcher.group(1);
4749
String className = matcher.group(2);
48-
String end_attributes = matcher.group(3);
50+
String endAttributes = matcher.group(3);
4951

5052
// add source file attribute
5153
String fileAttribute = "";
@@ -54,12 +56,12 @@ public void executionFinished(
5456
}
5557
String newTestCase =
5658
"<testcase"
57-
+ beg_attributes
59+
+ begAttributes
5860
+ "classname=\""
5961
+ className
6062
+ "\""
6163
+ fileAttribute
62-
+ end_attributes
64+
+ endAttributes
6365
+ ">";
6466
matcher.appendReplacement(result, newTestCase);
6567
}
@@ -68,7 +70,9 @@ public void executionFinished(
6870

6971
// set old filePath to new xml result
7072
// System.out.println("result: " + result);
71-
Files.write(filePath, result.toString().getBytes()); // does not work
73+
BufferedWriter writer = new BufferedWriter(new FileWriter(pathString));
74+
writer.write(result.toString());
75+
writer.close();
7276
} catch (Exception e) {
7377
System.out.println("Modifying XML files did not work.");
7478
}

0 commit comments

Comments
 (0)