10BC8 IO-314 Deprecate all methods that use the default encoding · apache/commons-io@fe0db49 · GitHub
Skip to content

Commit fe0db49

Browse files
committed
IO-314 Deprecate all methods that use the default encoding
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1468992 13f79535-47bb-0310-9956-ffa450edef68
1 parent b0a68db commit fe0db49

7 files changed

Lines changed: 69 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,9 @@ public static String readFileToString(final File file, final String encoding) th
17441744
* @return the file contents, never {@code null}
17451745
* @throws IOException in case of an I/O error
17461746
* @since 1.3.1
1747+
* @deprecated 2.5 use {@link #readFileToString(File, Charset)} instead
17471748
*/
1749+
@Deprecated
17481750
public static String readFileToString(final File file) throws IOException {
17491751
return readFileToString(file, Charset.defaultCharset());
17501752
}
@@ -1815,7 +1817,9 @@ public static List<String> readLines(final File file, final String encoding) thr
18151817
* @return the list of Strings representing each line in the file, never {@code null}
18161818
* @throws IOException in case of an I/O error
18171819
* @since 1.3
1820+
* @deprecated 2.5 use {@link #readLines(File, Charset)} instead
18181821
*/
1822+
@Deprecated
18191823
public static List<String> readLines(final File file) throws IOException {
18201824
return readLines(file, Charset.defaultCharset());
18211825
}
@@ -1958,7 +1962,9 @@ public static void writeStringToFile(final File file, final String data, final S
19581962
* @param file the file to write
19591963
* @param data the content to write to the file
19601964
* @throws IOException in case of an I/O error
1965+
* @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset)} instead
19611966
*/
1967+
@Deprecated
19621968
public static void writeStringToFile(final File file, final String data) throws IOException {
19631969
writeStringToFile(file, data, Charset.defaultCharset(), false);
19641970
}
@@ -1972,7 +1978,9 @@ public static void writeStringToFile(final File file, final String data) throws
19721978
* end of the file rather than overwriting
19731979
* @throws IOException in case of an I/O error
19741980
* @since 2.1
1981+
* @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset, boolean)} instead
19751982
*/
1983+
@Deprecated
19761984
public static void writeStringToFile(final File file, final String data, final boolean append) throws IOException {
19771985
writeStringToFile(file, data, Charset.defaultCharset(), append);
19781986
}
@@ -1984,7 +1992,9 @@ public static void writeStringToFile(final File file, final String data, final b
19841992
* @param data the content to write to the file
19851993
* @throws IOException in case of an I/O error
19861994
* @since 2.0
1995+
* @deprecated 2.5 use {@link #write(File, CharSequence, Charset)} instead
19871996
*/
1997+
@Deprecated
19881998
public static void write(final File file, final CharSequence data) throws IOException {
19891999
write(file, data, Charset.defaultCharset(), false);
19902000
}
@@ -1998,7 +2008,9 @@ public static void write(final File file, final CharSequence data) throws IOExce
19982008
* end of the file rather than overwriting
19992009
* @throws IOException in case of an I/O error
20002010
* @since 2.1
2011+
* @deprecated 2.5 use {@link #write(File, CharSequence, Charset, boolean)} instead
20012012
*/
2013+
@Deprecated
20022014
public static void write(final File file, final CharSequence data, final boolean append) throws IOException {
20032015
write(file, data, Charset.defaultCharset(), append);
20042016
}

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,9 @@ public static byte[] toByteArray(final InputStream input, final int size) throws
537537
* @return the requested byte array
538538
* @throws NullPointerException if the input is null
539539
* @throws IOException if an I/O error occurs
540+
* @deprecated 2.5 use {@link #toByteArray(Reader, Charset)} instead
540541
*/
542+
@Deprecated
541543
public static byte[] toByteArray(final Reader input) throws IOException {
542544
return toByteArray(input, Charset.defaultCharset());
543545
}
@@ -596,7 +598,7 @@ public static byte[] toByteArray(final Reader input, final String encoding) thro
596598
* @return the requested byte array
597599
* @throws NullPointerException if the input is null
598600
* @throws IOException if an I/O error occurs (never occurs)
599-
* @deprecated Use {@link String#getBytes()}
601+
* @deprecated 2.5 Use {@link String#getBytes()} instead
600602
*/
601603
@Deprecated
602604
public static byte[] toByteArray(final String input) throws IOException {
@@ -676,7 +678,9 @@ public static byte[] toByteArray(final URLConnection urlConn) throws IOException
676678
* @throws NullPointerException if the input is null
677679
* @throws IOException if an I/O error occurs
678680
* @since 1.1
681+
* @deprecated 2.5 use {@link #toCharArray(InputStream, Charset)} instead
679682
*/
683+
@Deprecated
680684
public static char[] toCharArray(final InputStream is) throws IOException {
681685
return toCharArray(is, Charset.defaultCharset());
682686
}
@@ -757,7 +761,9 @@ public static char[] toCharArray(final Reader input) throws IOException {
757761
* @return the requested String
758762
* @throws NullPointerException if the input is null
759763
* @throws IOException if an I/O error occurs
764+
* @deprecated 2.5 use {@link #toString(InputStream, Charset)} instead
760765
*/
766+
@Deprecated
761767
public static String toString(final InputStream input) throws IOException {
762768
return toString(input, Charset.defaultCharset());
763769
}
@@ -831,7 +837,9 @@ public static String toString(final Reader input) throws IOException {
831837
* @return The contents of the URL as a String.
832838
* @throws IOException if an I/O exception occurs.
833839
* @since 2.1
840+
* @deprecated 2.5 use {@link #toString(URI, Charset)} instead
834841
*/
842+
@Deprecated
835843
public static String toString(final URI uri) throws IOException {
836844
return toString(uri, Charset.defaultCharset());
837845
}
@@ -877,7 +885,9 @@ public static String toString(final URI uri, final String encoding) throws IOExc
877885
* @return The contents of the URL as a String.
878886
* @throws IOException if an I/O exception occurs.
879887
* @since 2.1
888+
* @deprecated 2.5 use {@link #toString(URL, Charset)} instead
880889
*/
890+
@Deprecated
881891
public static String toString(final URL url) throws IOException {
882892
return toString(url, Charset.defaultCharset());
883893
}
@@ -928,7 +938,7 @@ public static String toString(final URL url, final String encoding) throws IOExc
928938
* @return the requested String
929939
* @throws NullPointerException if the input is null
930940
* @throws IOException if an I/O error occurs (never occurs)
931-
* @deprecated Use {@link String#String(byte[])}
941+
* @deprecated 2.5 Use {@link String#String(byte[])} instead
932942
*/
933943
@Deprecated
934944
public static String toString(final byte[] input) throws IOException {
@@ -967,7 +977,9 @@ public static String toString(final byte[] input, final String encoding) throws
967977
* @throws NullPointerException if the input is null
968978
* @throws IOException if an I/O error occurs
969979
* @since 1.1
980+
* @deprecated 2.5 use {@link #readLines(InputStream, Charset)} instead
970981
*/
982+
@Deprecated
971983
public static List<String> readLines(final InputStream input) throws IOException {
972984
return readLines(input, Charset.defaultCharset());
973985
}
@@ -1151,7 +1163,9 @@ public static LineIterator lineIterator(final InputStream input, final String en
11511163
* @param input the CharSequence to convert
11521164
* @return an input stream
11531165
* @since 2.0
1166+
* @deprecated 2.5 use {@link #toInputStream(CharSequence, Charset)} instead
11541167
*/
1168+
@Deprecated
11551169
public static InputStream toInputStream(final CharSequence input) {
11561170
return toInputStream(input, Charset.defaultCharset());
11571171
}
@@ -1197,7 +1211,9 @@ public static InputStream toInputStream(final CharSequence input, final String e
11971211
* @param input the string to convert
11981212
* @return an input stream
11991213
* @since 1.1
1214+
* @deprecated 2.5 use {@link #toInputStream(String, Charset)} instead
12001215
*/
1216+
@Deprecated
12011217
public static InputStream toInputStream(final String input) {
12021218
return toInputStream(input, Charset.defaultCharset());
12031219
}
@@ -1267,7 +1283,9 @@ public static void write(final byte[] data, final OutputStream output)
12671283
* @throws NullPointerException if output is null
12681284
* @throws IOException if an I/O error occurs
12691285
* @since 1.1
1286+
* @deprecated 2.5 use {@link #write(byte[], Writer, Charset)} instead
12701287
*/
1288+
@Deprecated
12711289
public static void write(final byte[] data, final Writer output) throws IOException {
12721290
write(data, output, Charset.defaultCharset());
12731291
}
@@ -1348,7 +1366,9 @@ public static void write(final char[] data, final Writer output) throws IOExcept
13481366
* @throws NullPointerException if output is null
13491367
* @throws IOException if an I/O error occurs
13501368
* @since 1.1
1369+
* @deprecated 2.5 use {@link #write(char[], OutputStream, Charset)} instead
13511370
*/
1371+
@Deprecated
13521372
public static void write(final char[] data, final OutputStream output)
13531373
throws IOException {
13541374
write(data, output, Charset.defaultCharset());
@@ -1430,7 +1450,9 @@ public static void write(final CharSequence data, final Writer output) throws IO
14301450
* @throws NullPointerException if output is null
14311451
* @throws IOException if an I/O error occurs
14321452
* @since 2.0
1453+
* @deprecated 2.5 use {@link #write(CharSequence, OutputStream, Charset)} instead
14331454
*/
1455+
@Deprecated
14341456
public static void write(final CharSequence data, final OutputStream output)
14351457
throws IOException {
14361458
write(data, output, Charset.defaultCharset());
@@ -1507,7 +1529,9 @@ public static void write(final String data, final Writer output) throws IOExcept
15071529
* @throws NullPointerException if output is null
15081530
* @throws IOException if an I/O error occurs
15091531
* @since 1.1
1532+
* @deprecated 2.5 use {@link #write(String, OutputStream, Charset)} instead
15101533
*/
1534+
@Deprecated
15111535
public static void write(final String data, final OutputStream output)
15121536
throws IOException {
15131537
write(data, output, Charset.defaultCharset());
@@ -1636,7 +1660,9 @@ public static void write(final StringBuffer data, final OutputStream output, fin
16361660
* @throws NullPointerException if the output is null
16371661
* @throws IOException if an I/O error occurs
16381662
* @since 1.1
1663+
* @deprecated 2.5 use {@link #writeLines(Collection, String, OutputStream, Charset)} instead
16391664
*/
1665+
@Deprecated
16401666
public static void writeLines(final Collection<?> lines, final String lineEnding,
16411667
final OutputStream output) throws IOException {
16421668
writeLines(lines, lineEnding, output, Charset.defaultCharset());
@@ -1918,7 +1944,9 @@ public static long copyLarge(final InputStream input, final OutputStream output,
19181944
* @throws NullPointerException if the input or output is null
19191945
* @throws IOException if an I/O error occurs
19201946
* @since 1.1
1947+
* @deprecated 2.5 use {@link #copy(InputStream, Writer, Charset)} instead
19211948
*/
1949+
@Deprecated
19221950
public static void copy(final InputStream input, final Writer output)
19231951
throws IOException {
19241952
copy(input, output, Charset.defaultCharset());
@@ -2129,7 +2157,9 @@ public static long copyLarge(final Reader input, final Writer output, final long
21292157
* @throws NullPointerException if the input or output is null
21302158
* @throws IOException if an I/O error occurs
21312159
* @since 1.1
2160+
* @deprecated 2.5 use {@link #copy(Reader, OutputStream, Charset)} instead
21322161
*/
2162+
@Deprecated
21332163
public static void copy(final Reader input, final OutputStream output)
21342164
throws IOException {
21352165
copy(input, output, Charset.defaultCharset());

src/main/java/org/apache/commons/io/input/ReaderInputStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ public ReaderInputStream(final Reader reader, final String charsetName) {
177177
* with a default input buffer size of 1024 characters.
178178
*
179179
* @param reader the target {@link Reader}
180+
* @deprecated 2.5 use {@link #ReaderInputStream(Reader, Charset)} instead
180181
*/
182+
@Deprecated
181183
public ReaderInputStream(final Reader reader) {
182184
this(reader, Charset.defaultCharset());
183185
}

src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,25 @@ public class ReversedLinesFileReader implements Closeable {
5858
* @param file
5959
* the file to be read
6060
* @throws IOException if an I/O error occurs
61+
* @deprecated 2.5 use {@link #ReversedLinesFileReader(File, Charset)} instead
6162
*/
63+
@Deprecated
6264
public ReversedLinesFileReader(final File file) throws IOException {
63-
this(file, 4096, Charset.defaultCharset().toString());
65+
this(file, 4096, Charset.defaultCharset());
66+
}
67+
68+
/**
69+
* Creates a ReversedLinesFileReader with default block size of 4KB and the
70+
* specified encoding.
71+
*
72+
* @param file
73+
* the file to be read
74+
* @param charset the encoding to use
75+
* @throws IOException if an I/O error occurs
76+
* @since 2.5
77+
*/
78+
public ReversedLinesFileReader(final File file, final Charset charset) throws IOException {
79+
this(file, 4096, charset);
6480
}
6581

6682
/**

src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,10 @@ public synchronized byte[] toByteArray() {
353353
* using the platform default charset.
354354
* @return the contents of the byte array as a String
355355
* @see java.io.ByteArrayOutputStream#toString()
356+
* @deprecated 2.5 use {@link #toString(String)} instead
356357
*/
357358
@Override
359+
@Deprecated
358360
public String toString() {
359361
// make explicit the use of the default charset
360362
return new String(toByteArray(), Charset.defaultCharset());

src/main/java/org/apache/commons/io/output/LockableFileWriter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public LockableFileWriter(final File file, final boolean append) throws IOExcept
131131
* @param lockDir the directory in which the lock file should be held
132132
* @throws NullPointerException if the file is null
133133
* @throws IOException in case of an I/O error
134+
* @deprecated 2.5 use {@link #LockableFileWriter(File, Charset, boolean, String)} instead
134135
*/
136+
@Deprecated
135137
public LockableFileWriter(final File file, final boolean append, final String lockDir) throws IOException {
136138
this(file, Charset.defaultCharset(), append, lockDir);
137139
}

src/main/java/org/apache/commons/io/output/WriterOutputStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ public WriterOutputStream(final Writer writer, final String charsetName) {
192192
* be flushed when it overflows or when {@link #flush()} or {@link #close()} is called.
193193
*
194194
* @param writer the target {@link Writer}
195+
* @deprecated 2.5 use {@link #WriterOutputStream(Writer, Charset)} instead
195196
*/
197+
@Deprecated
196198
public WriterOutputStream(final Writer writer) {
197199
this(writer, Charset.defaultCharset(), DEFAULT_BUFFER_SIZE, false);
198200
}

0 commit comments

Comments
 (0)