English 中文(简体)
Java sURLConnection not received all binary file
原标题:Java s URLConnection not receiving entire binary file

目前,我正在学校中工作,其中包括建立一个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。

最佳回答

你们怎样知道, by的最高限额是15040? 你们是不是ArrayOut.toByteArray().length,还是你做了新的尝试(byte ArrayOut.toByteArray())。

从具有双向内容的单体阵列中创造新的力量,可能会产生无法预测的结果。 使用文件OutputStream并打开文件。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签