Skip to content

Commit 81210eb

Browse files
committed
Update BoundedReader.java
https://docs.oracle.com/javase/8/docs/api/java/io/Reader.html Add read bytes EOF test Patch by zhanhb <zhanhb88@gmail.com>, applied unmodified git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1746612 13f79535-47bb-0310-9956-ffa450edef68
1 parent 51f13c8 commit 81210eb

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public int read( char[] cbuf, int off, int len ) throws IOException {
139139
for ( int i = 0; i < len; i++ ) {
140140
c = read();
141141
if ( c == -1 ) {
142-
return i;
142+
return i == 0 ? -1 : i;
143143
}
144144
cbuf[off + i] = (char) c;
145145
}

src/test/java/org/apache/commons/io/input/BoundedReaderTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,12 @@ public void close()
181181
mr.close();
182182
assertTrue( closed.get() );
183183
}
184-
}
184+
185+
@Test(timeout = 5000)
186+
public void testReadBytesEOF() throws IOException {
187+
BoundedReader mr = new BoundedReader( sr, 3 );
188+
BufferedReader br = new BufferedReader( mr );
189+
br.readLine();
190+
br.readLine();
191+
}
192+
}

0 commit comments

Comments
 (0)