@@ -34,6 +34,28 @@ public class FilerUtil {
3434 this .processingEnv = processingEnv ;
3535 }
3636
37+ /**
38+ * This method uses the annotation processor Filer API and we shouldn't use a Path as paths containing \ are not supported.
39+ */
40+ public void write (String filePath , String value ) {
41+ if (value == null || value .isBlank ()) {
42+ return ;
43+ }
44+
45+ try {
46+ final FileObject listResource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" ,
47+ filePath );
48+
49+ try (BufferedWriter writer = new BufferedWriter (
50+ new OutputStreamWriter (listResource .openOutputStream (), StandardCharsets .UTF_8 ))) {
51+ writer .write (value );
52+ }
53+ } catch (IOException e ) {
54+ processingEnv .getMessager ().printMessage (Diagnostic .Kind .ERROR , "Failed to write " + filePath + ": " + e );
55+ return ;
56+ }
57+ }
58+
3759 /**
3860 * This method uses the annotation processor Filer API and we shouldn't use a Path as paths containing \ are not supported.
3961 */
@@ -44,7 +66,7 @@ public void write(String filePath, Set<String> set) {
4466
4567 try {
4668 final FileObject listResource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" ,
47- filePath . toString () );
69+ filePath );
4870
4971 try (BufferedWriter writer = new BufferedWriter (
5072 new OutputStreamWriter (listResource .openOutputStream (), StandardCharsets .UTF_8 ))) {
@@ -69,7 +91,7 @@ public void write(String filePath, Properties properties) {
6991
7092 try {
7193 final FileObject propertiesResource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" ,
72- filePath . toString () );
94+ filePath );
7395
7496 try (BufferedWriter writer = new BufferedWriter (
7597 new OutputStreamWriter (propertiesResource .openOutputStream (), StandardCharsets .UTF_8 ))) {
@@ -91,7 +113,7 @@ public void writeJson(String filePath, Object value) {
91113
92114 try {
93115 final FileObject jsonResource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" ,
94- filePath . toString () );
116+ filePath );
95117
96118 try (OutputStream os = jsonResource .openOutputStream ()) {
97119 JacksonMappers .jsonObjectWriter ().writeValue (os , value );
@@ -112,7 +134,7 @@ public void writeYaml(String filePath, Object value) {
112134
113135 try {
114136 final FileObject yamlResource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" ,
115- filePath . toString () );
137+ filePath );
116138
117139 try (OutputStream os = yamlResource .openOutputStream ()) {
118140 JacksonMappers .yamlObjectWriter ().writeValue (os , value );
0 commit comments