Skip to content

Commit 3e94738

Browse files
committed
IO-233 IO-330 Add Methods for Buffering Streams/Writers To IOUtils
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1483859 13f79535-47bb-0310-9956-ffa450edef68
1 parent 626bad7 commit 3e94738

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/changes/changes.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ The <action> type attribute can be add,update,fix,remove.
4747
<body>
4848
<!-- The release date is the date RC is cut -->
4949
<release version="2.5" date="2013-??-??" description="New features and bug fixes.">
50+
<action issue="IO-233" dev="sebb" type="add">
51+
Add Methods for Buffering Streams/Writers To IOUtils
52+
Added overloaded buffer() methods - see also IO-330
53+
</action>
54+
<action issue="IO-330" dev="sebb" type="add">
55+
IOUtils#toBufferedOutputStream/toBufferedWriter to conditionally wrap the output
56+
Added overloaded buffer() methods - see also IO-233
57+
</action>
5058
<action issue="IO-381" dev="ggregory" type="add">
5159
Add FileUtils.copyInputStreamToFile API with option to leave the source open.
5260
See copyInputStreamToFile(final InputStream source, final File destination, boolean closeSource)
@@ -74,10 +82,6 @@ The <action> type attribute can be add,update,fix,remove.
7482
FileUtils.listFilesAndDirs includes original dir in results even when it doesn't match filter
7583
Javadoc: clarify that original dir is included in the results
7684
</action>
77-
<action issue="IO-330" dev="sebb" type="add">
78-
IOUtils#toBufferedOutputStream/toBufferedWriter to conditionally wrap the output
79-
Added asBufferedInputStream, asBufferedOutputStream, asBufferedReader, asBufferedWriter
80-
</action>
8185
<action issue="IO-346" dev="sebb" type="add">
8286
Add ByteArrayOutputStream.toInputStream()
8387
</action>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public static InputStream toBufferedInputStream(final InputStream input) throws
443443
* the reader to wrap or return (not null)
444444
* @return the given reader or a new {@link BufferedReader} for the given reader
445445
* @since 2.2
446-
* @see #asBufferedReader(Reader)
446+
* @see #buffer(Reader)
447447
* @throws NullPointerException if the input parameter is null
448448
*/
449449
public static BufferedReader toBufferedReader(final Reader reader) {
@@ -460,7 +460,7 @@ public static BufferedReader toBufferedReader(final Reader reader) {
460460
* @since 2.5
461461
* @throws NullPointerException if the input parameter is null
462462
*/
463-
public static BufferedReader asBufferedReader(final Reader reader) {
463+
public static BufferedReader buffer(final Reader reader) {
464464
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
465465
}
466466

@@ -474,7 +474,7 @@ public static BufferedReader asBufferedReader(final Reader reader) {
474474
* @since 2.5
475475
* @throws NullPointerException if the input parameter is null
476476
*/
477-
public static BufferedWriter asBufferedWriter(final Writer writer) {
477+
public static BufferedWriter buffer(final Writer writer) {
478478
return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer);
479479
}
480480

@@ -488,7 +488,7 @@ public static BufferedWriter asBufferedWriter(final Writer writer) {
488488
* @since 2.5
489489
* @throws NullPointerException if the input parameter is null
490490
*/
491-
public static BufferedOutputStream asBufferedOutputStream(final OutputStream outputStream) {
491+
public static BufferedOutputStream buffer(final OutputStream outputStream) {
492492
// reject null early on rather than waiting for IO operation to fail
493493
if (outputStream == null) { // not checked by BufferedOutputStream
494494
throw new NullPointerException();
@@ -506,7 +506,7 @@ public static BufferedOutputStream asBufferedOutputStream(final OutputStream out
506506
* @since 2.5
507507
* @throws NullPointerException if the input parameter is null
508508
*/
509-
public static BufferedInputStream asBufferedInputStream(final InputStream inputStream) {
509+
public static BufferedInputStream buffer(final InputStream inputStream) {
510510
// reject null early on rather than waiting for IO operation to fail
511511
if (inputStream == null) { // not checked by BufferedInputStream
512512
throw new NullPointerException();

src/test/java/org/apache/commons/io/IOUtilsTestCase.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,25 +1212,25 @@ public void testToString_URL_CharsetNameNull() throws Exception {
12121212

12131213
public void testAsBufferedNull() {
12141214
try {
1215-
IOUtils.asBufferedInputStream(null);
1215+
IOUtils.buffer((InputStream) null);
12161216
fail("Expected NullPointerException");
12171217
} catch (NullPointerException npe) {
12181218
// expected
12191219
}
12201220
try {
1221-
IOUtils.asBufferedOutputStream(null);
1221+
IOUtils.buffer((OutputStream) null);
12221222
fail("Expected NullPointerException");
12231223
} catch (NullPointerException npe) {
12241224
// expected
12251225
}
12261226
try {
1227-
IOUtils.asBufferedReader(null);
1227+
IOUtils.buffer((Reader) null);
12281228
fail("Expected NullPointerException");
12291229
} catch (NullPointerException npe) {
12301230
// expected
12311231
}
12321232
try {
1233-
IOUtils.asBufferedWriter(null);
1233+
IOUtils.buffer((Writer) null);
12341234
fail("Expected NullPointerException");
12351235
} catch (NullPointerException npe) {
12361236
// expected
@@ -1244,19 +1244,19 @@ public int read() throws IOException {
12441244
return 0;
12451245
}
12461246
};
1247-
final BufferedInputStream bis = IOUtils.asBufferedInputStream(is);
1247+
final BufferedInputStream bis = IOUtils.buffer(is);
12481248
assertNotSame(is, bis);
1249-
assertSame(bis, IOUtils.asBufferedInputStream(bis));
1249+
assertSame(bis, IOUtils.buffer(bis));
12501250
}
12511251

12521252
public void testAsBufferedOutputStream() {
12531253
OutputStream is = new OutputStream() {
12541254
@Override
12551255
public void write(int b) throws IOException { }
12561256
};
1257-
final BufferedOutputStream bis = IOUtils.asBufferedOutputStream(is);
1257+
final BufferedOutputStream bis = IOUtils.buffer(is);
12581258
assertNotSame(is, bis);
1259-
assertSame(bis, IOUtils.asBufferedOutputStream(bis));
1259+
assertSame(bis, IOUtils.buffer(bis));
12601260
}
12611261

12621262
public void testAsBufferedReader() {
@@ -1268,9 +1268,9 @@ public int read(char[] cbuf, int off, int len) throws IOException {
12681268
@Override
12691269
public void close() throws IOException { }
12701270
};
1271-
final BufferedReader bis = IOUtils.asBufferedReader(is);
1271+
final BufferedReader bis = IOUtils.buffer(is);
12721272
assertNotSame(is, bis);
1273-
assertSame(bis, IOUtils.asBufferedReader(bis));
1273+
assertSame(bis, IOUtils.buffer(bis));
12741274
}
12751275

12761276
public void testAsBufferedWriter() {
@@ -1287,8 +1287,8 @@ public void flush() throws IOException { }
12871287
@Override
12881288
public void close() throws IOException { }
12891289
};
1290-
final BufferedWriter bis = IOUtils.asBufferedWriter(is);
1290+
final BufferedWriter bis = IOUtils.buffer(is);
12911291
assertNotSame(is, bis);
1292-
assertSame(bis, IOUtils.asBufferedWriter(bis));
1292+
assertSame(bis, IOUtils.buffer(bis));
12931293
}
12941294
}

0 commit comments

Comments
 (0)