Skip to content

Commit 493a38a

Browse files
committed
Make explicit where the default platform encoding is being used
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1468883 13f79535-47bb-0310-9956-ffa450edef68
1 parent 51f1efb commit 493a38a

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/main/java/org/apache/commons/io/FileSystemUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.InputStream;
2323
import java.io.InputStreamReader;
2424
import java.io.OutputStream;
25+
import java.nio.charset.Charset;
2526
import java.util.ArrayList;
2627
import java.util.Arrays;
2728
import java.util.List;
@@ -483,7 +484,8 @@ List<String> performCommand(final String[] cmdAttribs, final int max, final long
483484
in = proc.getInputStream();
484485
out = proc.getOutputStream();
485486
err = proc.getErrorStream();
486-
inr = new BufferedReader(new InputStreamReader(in));
487+
// default charset is most likely appropriate here
488+
inr = new BufferedReader(new InputStreamReader(in, Charset.defaultCharset()));
487489
String line = inr.readLine();
488490
while (line != null && lines.size() < max) {
489491
line = line.toLowerCase(Locale.ENGLISH).trim();

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,9 @@ public static boolean contentEqualsIgnoreEOL(final File file1, final File file2,
808808
Reader input2 = null;
809809
try {
810810
if (charsetName == null) {
811-
input1 = new InputStreamReader(new FileInputStream(file1));
812-
input2 = new InputStreamReader(new FileInputStream(file2));
811+
// N.B. make explicit the use of the default charset
812+
input1 = new InputStreamReader(new FileInputStream(file1), Charset.defaultCharset());
813+
input2 = new InputStreamReader(new FileInputStream(file2), Charset.defaultCharset());
813814
} else {
814815
input1 = new InputStreamReader(new FileInputStream(file1), charsetName);
815816
input2 = new InputStreamReader(new FileInputStream(file2), charsetName);

src/main/java/org/apache/commons/io/HexDump.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.io.OutputStream;
21+
import java.nio.charset.Charset;
2122

2223
/**
2324
* Dumps data in hexadecimal format.
@@ -107,7 +108,8 @@ public static void dump(final byte[] data, final long offset,
107108
}
108109
}
109110
buffer.append(EOL);
110-
stream.write(buffer.toString().getBytes());
111+
// make explicit the dependency on the default encoding
112+
stream.write(buffer.toString().getBytes(Charset.defaultCharset()));
111113
stream.flush();
112114
buffer.setLength(0);
113115
display_offset += chars_read;

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ public static byte[] toByteArray(final Reader input, final String encoding) thro
600600
*/
601601
@Deprecated
602602
public static byte[] toByteArray(final String input) throws IOException {
603-
return input.getBytes();
603+
// make explicit the use of the default charset
604+
return input.getBytes(Charset.defaultCharset());
604605
}
605606

606607
/**
@@ -931,7 +932,8 @@ public static String toString(final URL url, final String encoding) throws IOExc
931932
*/
932933
@Deprecated
933934
public static String toString(final byte[] input) throws IOException {
934-
return new String(input);
935+
// make explicit the use of the default charset
936+
return new String(input, Charset.defaultCharset());
935937
}
936938

937939
/**

0 commit comments

Comments
 (0)