Skip to content

Commit cb76dbe

Browse files
committed
AbstractOrigin.getReader(Charset) now maps a null Charset to the default
Charset - org.apache.commons.io.build.AbstractOrigin.getReader(Charset) now maps a null Charset to the default Charset - org.apache.commons.io.build.AbstractOrigin.AbstractRandomAccessFileOrigin.getReader(Charset) now maps a null Charset to the default Charset - org.apache.commons.io.build.AbstractOrigin.ByeArrayOrigin.getReader(Charset) now maps a null Charset to the default Charset - org.apache.commons.io.build.AbstractOrigin.InputStreamOrigin.getReader(Charset) now maps a null Charset to the default Charset
1 parent 41419d1 commit cb76dbe

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/changes/changes.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ The <action> type attribute can be add,update,fix,remove.
4747
<body>
4848
<release version="2.20.0" date="YYYY-MM-DD" description="Version 2.19.1: Java 8 or later is required.">
4949
<!-- FIX -->
50-
<action dev="ggregory" type="fix" due-to="Jesse Glick">[javadoc] Rename parameter of ProxyOutputStream.write(int) #740.</action>
51-
<action dev="ggregory" type="fix" issue="IO-875" due-to="Pierre Baumard, Gary Gregory">CopyDirectoryVisitor ignores fileFilter #743.</action>
50+
<action dev="ggregory" type="fix" due-to="Jesse Glick">[javadoc] Rename parameter of ProxyOutputStream.write(int) #740.</action>
51+
<action dev="ggregory" type="fix" issue="IO-875" due-to="Pierre Baumard, Gary Gregory">CopyDirectoryVisitor ignores fileFilter #743.</action>
52+
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.getReader(Charset) now maps a null Charset to the default Charset.</action>
53+
<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>
54+
<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>
55+
<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>
5256
<!-- ADD -->
5357
<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>
5458
<!-- UPDATE -->

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Arrays;
4040
import java.util.Objects;
4141

42+
import org.apache.commons.io.Charsets;
4243
import org.apache.commons.io.IORandomAccessFile;
4344
import org.apache.commons.io.IOUtils;
4445
import org.apache.commons.io.RandomAccessFileMode;
@@ -128,7 +129,7 @@ public T getRandomAccessFile(final OpenOption... openOption) {
128129

129130
@Override
130131
public Reader getReader(final Charset charset) throws IOException {
131-
return new InputStreamReader(getInputStream(), charset);
132+
return new InputStreamReader(getInputStream(), Charsets.toCharset(charset));
132133
}
133134

134135
@Override
@@ -175,7 +176,7 @@ public InputStream getInputStream(final OpenOption... options) throws IOExceptio
175176

176177
@Override
177178
public Reader getReader(final Charset charset) throws IOException {
178-
return new InputStreamReader(getInputStream(), charset);
179+
return new InputStreamReader(getInputStream(), Charsets.toCharset(charset));
179180
}
180181

181182
@Override
@@ -320,7 +321,7 @@ public InputStream getInputStream(final OpenOption... options) {
320321

321322
@Override
322323
public Reader getReader(final Charset charset) throws IOException {
323-
return new InputStreamReader(getInputStream(), charset);
324+
return new InputStreamReader(getInputStream(), Charsets.toCharset(charset));
324325
}
325326

326327
}
@@ -729,12 +730,12 @@ public RandomAccessFile getRandomAccessFile(final OpenOption... openOption) thro
729730
/**
730731
* Gets a new Reader on the origin, buffered by default.
731732
*
732-
* @param charset the charset to use for decoding
733+
* @param charset the charset to use for decoding, null maps to the default Charset.
733734
* @return a new Reader on the origin.
734735
* @throws IOException if an I/O error occurs opening the file.
735736
*/
736737
public Reader getReader(final Charset charset) throws IOException {
737-
return Files.newBufferedReader(getPath(), charset);
738+
return Files.newBufferedReader(getPath(), Charsets.toCharset(charset));
738739
}
739740

740741
private String getSimpleClassName() {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ public void testGetReader() throws IOException {
224224
try (Reader reader = getOriginRo().getReader(Charset.defaultCharset())) {
225225
assertNotNull(reader);
226226
}
227+
try (Reader reader = getOriginRo().getReader(null)) {
228+
assertNotNull(reader);
229+
}
227230
}
228231

229232
@Test

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ public void testGetReaderIgnoreCharset() throws IOException {
100100
}
101101
}
102102

103+
@Test
104+
public void testGetReaderIgnoreCharsetNull() throws IOException {
105+
// The CharSequenceOrigin ignores the given Charset.
106+
try (Reader reader = getOriginRo().getReader(null)) {
107+
assertNotNull(reader);
108+
assertEquals(getFixtureStringFromFile(), IOUtils.toString(reader));
109+
}
110+
}
111+
103112
@Override
104113
@Test
105114
public void testGetWriter() {

0 commit comments

Comments
 (0)