Skip to content

Fix Properties.store(OutputStream os, String comment) #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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