Skip to content

Commit 2d98a64

Browse files
gastaldiquintesse
authored andcommitted
Fix Properties.store(OutputStream os, String comment)
This fixes the store method taking an `OutputStream` by flushing and closing the writer created to wrap it.
1 parent f03fe7e commit 2d98a64

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@
187187
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
188188
</repository>
189189
</distributionManagement>
190-
</project>
190+
</project>

src/main/java/org/codejive/properties/Properties.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,9 @@ public void store(Path file, String... comment) throws IOException {
910910
* @throws IOException Thrown when any IO error occurs during operation
911911
*/
912912
public void store(OutputStream out, String... comment) throws IOException {
913-
store(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1), comment);
913+
store(
914+
new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1)),
915+
comment);
914916
}
915917

916918
/**
@@ -938,6 +940,7 @@ public void store(Writer writer, String... comment) throws IOException {
938940
writer.write(pos.raw());
939941
pos.next();
940942
}
943+
writer.flush();
941944
}
942945

943946
/**

src/test/java/org/codejive/properties/TestProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ void testStore() throws IOException, URISyntaxException {
118118
assertThat(sw.toString()).isEqualTo(readAll(f));
119119
}
120120

121+
@Test
122+
void testStoreOutputStream() throws IOException, URISyntaxException {
123+
Path f = getResource("/test-escaped.properties");
124+
Properties p = Properties.loadProperties(f);
125+
ByteArrayOutputStream os = new ByteArrayOutputStream();
126+
p.store(os);
127+
assertThat(os.toString()).isEqualTo(readAll(f));
128+
}
129+
121130
@Test
122131
void testStoreCrLf() throws IOException, URISyntaxException {
123132
Path f = getResource("/testcrlf.properties");

0 commit comments

Comments
 (0)