fix #360, add check for empty buffer; also add unit test for this scenario
This commit is contained in:
parent
c37496311c
commit
a6d7105761
@ -195,7 +195,8 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
lineBuf.append((char) b);
|
||||
}
|
||||
|
||||
while (lineBuf.charAt(lineBuf.length() - 1) == '\r') {
|
||||
while ( lineBuf.length() > 0 &&
|
||||
lineBuf.charAt(lineBuf.length() - 1) == '\r') {
|
||||
lineBuf.setLength(lineBuf.length() - 1);
|
||||
}
|
||||
|
||||
|
@ -168,4 +168,15 @@ public class ChannelBufferStreamTest {
|
||||
|
||||
assertEquals(buf.readerIndex(), in.readBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyReadLine() throws Exception {
|
||||
ChannelBuffer buf = ChannelBuffers.buffer(0);
|
||||
ChannelBufferInputStream in = new ChannelBufferInputStream(buf);
|
||||
|
||||
String s = in.readLine();
|
||||
assertEquals(0, s.length());
|
||||
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user