cbeust/testng — Issue #176: Incorrect return value when call ReadableByteChannel.read(ByteBuffer buffer)
Author: cqlangyi
Created: 2012-02-22 18:22:24+00:00
State: open

[code]
url = new URL(link);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();

// read return html
final InputStream ins = connection.getInputStream();
final ReadableByteChannel channel = Channels.newChannel(ins);
this.buffer.clear();
int byteCount = 0;
while (byteCount > -1) {
byteCount = channel.read(this.buffer);
System.out.println("read " + byteCount + " bytes.");
}

[issue]
when run this code in a main function, byteCount got -1 finally as the end of the stream.

but when run this code within testng suite, after read several bytes, the byteCound will
always be "0", and so go into a infinite loop.

[versions]
testng: 6.4
jdk: sun 1.6.31
eclipse: 3.7.1
ant: 1.8.2