目前,我正在学校中工作,其中包括建立一个P2P客户,以达到我们所制定的标准,即利用吉卜赛人协会向同龄人申请双双亲档案库。 允许我们Java s HTTP图书馆提出这些要求,然而,我正在对这些图书馆造成一个重大问题。 档案的所有空白都将在斜坡的丘库中提供;=64KB,但当我使用以下代码时,我收到的最大 by量约为15040,尽管答复的内容是64KB:
String response = "";
URL url = new URL(uriPath);
URLConnection conn = url.openConnection ();
conn.setConnectTimeout(30 * 1000);
conn.setReadTimeout(30 * 1000);
InputStream stream = conn.getInputStream();
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
int c;
byte[] buffer = new byte[4096];
while ((c = stream.read(buffer)) != -1)
{
byteArrayOut.write(buffer,0,c);
}
body = byteArrayOut.toByteArray();
stream.close();
result.put(Constants.HEADER_CONTENT_LENGTH, conn.getHeaderField(Constants.HEADER_CONTENT_LENGTH));
result.put(Constants.HEADER_CONTENT_CHECKSUM, conn.getHeaderField(Constants.HEADER_CONTENT_CHECKSUM));
result.put(Constants.KEY_BODY, new String(body));
We ve tested our server component, and that serves the file correctly when accessing a chunk with wget or in a browser - this java client is the only problematic client we were able to find.
Is this a problem with Java s URLConnection class, or is there something in my code that is wrong with reading a binary file that is returned in a response?
注:我从Eclipse和指挥线使用Java 1.6。