Merge back fix for #360

This commit is contained in:
norman 2012-05-24 08:45:48 +02:00
parent 98a8bd25bb
commit 1bc52cbd8c
2 changed files with 16 additions and 2 deletions

View File

@ -184,9 +184,12 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
lineBuf.append((char) b);
}
while (lineBuf.charAt(lineBuf.length() - 1) == '\r') {
lineBuf.setLength(lineBuf.length() - 1);
if (lineBuf.length() > 0) {
while (lineBuf.charAt(lineBuf.length() - 1) == '\r') {
lineBuf.setLength(lineBuf.length() - 1);
}
}
return lineBuf.toString();
}

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