Skip to content

Commit

Permalink
Fix Properties.store(OutputStream os, String comment)
Browse files Browse the repository at this point in the history
This fixes the store method taking an `OutputStream` by flushing and closing the writer created to wrap it.
  • Loading branch information
gastaldi authored and quintesse committed Jul 9, 2024
1 parent f03fe7e commit 2d98a64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project>
</project>
5 changes: 4 additions & 1 deletion src/main/java/org/codejive/properties/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,9 @@ public void store(Path file, String... comment) throws IOException {
* @throws IOException Thrown when any IO error occurs during operation
*/
public void store(OutputStream out, String... comment) throws IOException {
store(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1), comment);
store(
new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1)),
comment);
}

/**
Expand Down Expand Up @@ -938,6 +940,7 @@ public void store(Writer writer, String... comment) throws IOException {
writer.write(pos.raw());
pos.next();
}
writer.flush();
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/codejive/properties/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ void testStore() throws IOException, URISyntaxException {
assertThat(sw.toString()).isEqualTo(readAll(f));
}

@Test
void testStoreOutputStream() throws IOException, URISyntaxException {
Path f = getResource("/test-escaped.properties");
Properties p = Properties.loadProperties(f);
ByteArrayOutputStream os = new ByteArrayOutputStream();
p.store(os);
assertThat(os.toString()).isEqualTo(readAll(f));
}

@Test
void testStoreCrLf() throws IOException, URISyntaxException {
Path f = getResource("/testcrlf.properties");
Expand Down

0 comments on commit 2d98a64

Please sign in to comment.