fix #360, add check for empty buffer; also add unit test for this scenario

This commit is contained in:
Sun Ning 2012-05-24 14:33:19 +08:00 committed by Trustin Lee
parent 59b5c3a328
commit f2df20ddff
2 changed files with 13 additions and 1 deletions

View File

@ -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);
}

View File

@ -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();
}
}