HTTPヘッダーでチャンク化されたファイルを送信することでご存知かもしれませんが、コンテンツの長さはないため、プログラムはファイルが終了したことを理解するために0を待つ必要があります。
--sample http header
POST /some/path HTTP/1.1
Host: www.example.com
Content-Type: text/plain
Transfer-Encoding: chunked
25
This is the data in the first chunk
8
sequence
0
このファイルを受信するには、次のコードを使用できます。
ResponseHandler<String> reshandler = new ResponseHandler<String>() {
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
byte[] b = new byte[500];
StringBuffer out = new StringBuffer();
int len = in.read(b);
out.append(new String(b, 0 , len));
return out.toString();
}
};
しかし、私の場合、ストリーミングチャネルを使用しています。つまり、ファイルが終了したことを示す0はありません。とにかく、私がこのコードを使用する場合、それは決して起こらない0を待つために永遠に待つようです。私の質問は、ストリームチャネルからチャンクファイルを受信するためのより良いアプローチはありますか?