Skip to content

Commit e985392

Browse files
committed
AbstractOrigin.getWriter(Charset) now maps a null Charset to the default
Charset - org.apache.commons.io.build.AbstractOrigin.getWriter(Charset) now maps a null Charset to the default Charset - org.apache.commons.io.build.AbstractOrigin.AbstractRandomAccessFileOrigin.getWriter(Charset) now maps a null Charset to the default Charset - org.apache.commons.io.build.AbstractOrigin.OutputStreamOrigin.getWriter(Charset) now maps a null Charset to the default Charset
1 parent cb76dbe commit e985392

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ The <action> type attribute can be add,update,fix,remove.
5353
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.AbstractRandomAccessFileOrigin.getReader(Charset) now maps a null Charset to the default Charset.</action>
5454
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.ByeArrayOrigin.getReader(Charset) now maps a null Charset to the default Charset.</action>
5555
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.InputStreamOrigin.getReader(Charset) now maps a null Charset to the default Charset.</action>
56+
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.getWriter(Charset) now maps a null Charset to the default Charset.</action>
57+
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.AbstractRandomAccessFileOrigin.getWriter(Charset) now maps a null Charset to the default Charset.</action>
58+
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.OutputStreamOrigin.getWriter(Charset) now maps a null Charset to the default Charset.</action>
5659
<!-- ADD -->
5760
<action dev="ggregory" type="add" issue="IO-875" due-to="Pierre Baumard, Gary Gregory">Add and use org.apache.commons.io.file.CountingPathVisitor.accept(Path, BasicFileAttributes) #743.</action>
5861
<!-- UPDATE -->

src/main/java/org/apache/commons/io/build/AbstractOrigin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public Reader getReader(final Charset charset) throws IOException {
134134

135135
@Override
136136
public Writer getWriter(final Charset charset, final OpenOption... options) throws IOException {
137-
return new OutputStreamWriter(getOutputStream(options), charset);
137+
return new OutputStreamWriter(getOutputStream(options), Charsets.toCharset(charset));
138138
}
139139

140140
@Override
@@ -392,7 +392,7 @@ public OutputStream getOutputStream(final OpenOption... options) {
392392
*/
393393
@Override
394394
public Writer getWriter(final Charset charset, final OpenOption... options) throws IOException {
395-
return new OutputStreamWriter(origin, charset);
395+
return new OutputStreamWriter(origin, Charsets.toCharset(charset));
396396
}
397397
}
398398

@@ -752,7 +752,7 @@ private String getSimpleClassName() {
752752
* @throws UnsupportedOperationException if the origin cannot be converted to a Path.
753753
*/
754754
public Writer getWriter(final Charset charset, final OpenOption... options) throws IOException {
755-
return Files.newBufferedWriter(getPath(), charset, options);
755+
return Files.newBufferedWriter(getPath(), Charsets.toCharset(charset), options);
756756
}
757757

758758
/**

src/test/java/org/apache/commons/io/build/AbstractOriginTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ public void testGetWriter() throws IOException {
234234
try (Writer writer = getOriginRw().getWriter(Charset.defaultCharset())) {
235235
assertNotNull(writer);
236236
}
237+
setOriginRw(newOriginRw());
238+
try (Writer writer = getOriginRw().getWriter(null)) {
239+
assertNotNull(writer);
240+
}
237241
}
238242

239243
@Test

0 commit comments

Comments
 (0)