更新:无论我尝试接收多少数据,我都知道会出现相同的错误。任何可以帮助我解决此问题的想法和建议将不胜感激。
我正在尝试从 Web 服务中的成员列表中检索用户 ID 列表。不幸的是,在只收到了几个成员之后,我得到了一个“Stream is Closed”的 IOException。这是我第一次尝试检索这种规模的流(我们正在谈论 +100 个成员),也是我第一次收到此错误。
有问题的错误:
发生异常的代码:
private void setupRequest(OAuthRequest request)
{
request.setConnectionKeepAlive(true);
request.setConnectTimeout(60, TimeUnit.SECONDS);
request.addHeader("accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");
// request.addHeader("accept-encoding", "gzip, deflate");
request.addHeader("user-agent", m_sIDENTIFIER);
}
private String readStream(InputStream stream) throws IOException
{
String sReturn = "";
if(stream != null)
{
final BufferedReader bufReader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
final StringBuffer s2 = new StringBuffer();
String line = bufReader.readLine();
if(line != null)
{
s2.append(line);
while((line = bufReader.readLine()) != null)
{
s2.append('\n');
s2.append(line);
}
}
bufReader.close();
sReturn = s2.toString();
}
return sReturn;
}
private InputStream getResultStream(Response response) throws IOException
{
InputStream resultStream = null;
if(response != null)
{
String encoding = response.getHeader("Content-Encoding");
if((encoding != null) && (encoding.equalsIgnoreCase("gzip")))
{
Log.d("Stream :", "Read GZIP");
} else if ((encoding != null) && encoding.equalsIgnoreCase("deflate")) {
resultStream = new InflaterInputStream(response.getStream(), new Inflater(true));
Log.d("Stream :", "Read Deflated.");
} else {
resultStream = response.getStream();
Log.d("Stream :","Read Normal.");
}
}
return resultStream;
}
对导致问题的原因有任何想法吗?我收到的数据量有限制吗?