Skip to content

Commit aeaa4f7

Browse files
author
Brian Burkhalter
committedSep 26, 2024
8336895: BufferedReader doesn't read full \r\n line ending when it doesn't fit in buffer
Reviewed-by: jpai, alanb
1 parent 376056c commit aeaa4f7

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed
 

‎src/java.base/share/classes/java/io/BufferedInputStream.java

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
* reread before new bytes are taken from
5151
* the contained input stream.
5252
*
53+
* @apiNote
54+
* Once wrapped in a {@code BufferedInputStream}, the underlying
55+
* {@code InputStream} should not be used directly nor wrapped with
56+
* another stream.
57+
*
5358
* @author Arthur van Hoff
5459
* @since 1.0
5560
*/

‎src/java.base/share/classes/java/io/BufferedOutputStream.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,6 +35,11 @@
3535
* output stream without necessarily causing a call to the underlying
3636
* system for each byte written.
3737
*
38+
* @apiNote
39+
* Once wrapped in a {@code BufferedOutputStream}, the underlying
40+
* {@code OutputStream} should not be used directly nor wrapped with
41+
* another stream.
42+
*
3843
* @author Arthur van Hoff
3944
* @since 1.0
4045
*/

‎src/java.base/share/classes/java/io/BufferedReader.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,21 +43,28 @@
4343
*
4444
* <p> In general, each read request made of a Reader causes a corresponding
4545
* read request to be made of the underlying character or byte stream. It is
46-
* therefore advisable to wrap a BufferedReader around any Reader whose read()
47-
* operations may be costly, such as FileReaders and InputStreamReaders. For
46+
* therefore advisable to wrap a {@code BufferedReader} around any
47+
* {@code Reader} whose {@code read()} operations may be costly, such as
48+
* {@code FileReader}s and {@code InputStreamReader}s. For
4849
* example,
4950
*
5051
* {@snippet lang=java :
5152
* BufferedReader in = new BufferedReader(new FileReader("foo.in"));
5253
* }
5354
*
5455
* will buffer the input from the specified file. Without buffering, each
55-
* invocation of read() or readLine() could cause bytes to be read from the
56-
* file, converted into characters, and then returned, which can be very
57-
* inefficient.
56+
* invocation of {@code read()} or {@code readLine()} could cause bytes to be
57+
* read from the file, converted into characters, and then returned, which can
58+
* be very inefficient.
5859
*
59-
* <p> Programs that use DataInputStreams for textual input can be localized by
60-
* replacing each DataInputStream with an appropriate BufferedReader.
60+
* <p> Programs that use {@code DataInputStream}s for textual input can be
61+
* localized by replacing each {@code DataInputStream} with an appropriate
62+
* {@code BufferedReader}.
63+
*
64+
* @apiNote
65+
* Once wrapped in a {@code BufferedReader}, the underlying
66+
* {@code Reader} should not be used directly nor wrapped with
67+
* another reader.
6168
*
6269
* @see FileReader
6370
* @see InputStreamReader

‎src/java.base/share/classes/java/io/BufferedWriter.java

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,25 +37,31 @@
3737
* <p> The buffer size may be specified, or the default size may be accepted.
3838
* The default is large enough for most purposes.
3939
*
40-
* <p> A newLine() method is provided, which uses the platform's own notion of
41-
* line separator as defined by the system property {@code line.separator}.
42-
* Not all platforms use the newline character ('\n') to terminate lines.
43-
* Calling this method to terminate each output line is therefore preferred to
44-
* writing a newline character directly.
40+
* <p> A {@code newLine()} method is provided, which uses the platform's own
41+
* notion of line separator as defined by the system property
42+
* {@linkplain System#lineSeparator() line.separator}. Not all platforms use the newline character ('\n')
43+
* to terminate lines. Calling this method to terminate each output line is
44+
* therefore preferred to writing a newline character directly.
4545
*
46-
* <p> In general, a Writer sends its output immediately to the underlying
47-
* character or byte stream. Unless prompt output is required, it is advisable
48-
* to wrap a BufferedWriter around any Writer whose write() operations may be
49-
* costly, such as FileWriters and OutputStreamWriters. For example,
46+
* <p> In general, a {@code Writer} sends its output immediately to the
47+
* underlying character or byte stream. Unless prompt output is required, it
48+
* is advisable to wrap a {@code BufferedWriter} around any {@code Writer} whose
49+
* {@code write()} operations may be costly, such as {@code FileWriter}s and
50+
* {@code OutputStreamWriter}s. For example,
5051
*
5152
* {@snippet lang=java :
5253
* PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
5354
* }
5455
*
55-
* will buffer the PrintWriter's output to the file. Without buffering, each
56-
* invocation of a print() method would cause characters to be converted into
57-
* bytes that would then be written immediately to the file, which can be very
58-
* inefficient.
56+
* will buffer the {@code PrintWriter}'s output to the file. Without buffering,
57+
* each invocation of a {@code print()} method would cause characters to be
58+
* converted into bytes that would then be written immediately to the file,
59+
* which can be very inefficient.
60+
*
61+
* @apiNote
62+
* Once wrapped in a {@code BufferedWriter}, the underlying
63+
* {@code Writer} should not be used directly nor wrapped with
64+
* another writer.
5965
*
6066
* @see PrintWriter
6167
* @see FileWriter

0 commit comments

Comments
 (0)
Please sign in to comment.