Effect of HttpUrlConnection.setChunkedStreamingMode

Viewed 5542

I don't get a good understanding about HttpUrlConnection.setChunkedStreamingMode, what is the effect of this mode?

I have following sample code:

HttpURLConnection conn = getHttpURLConnection(_url);
conn.setChunkedStreamingMode(4096); //4k
conn.setConnectTimeout(3000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStream out = conn.getOutputStream();
byte[] buffer = new byte[1024 * 10];//10k
FileInputStream in= new FileInputStream(file); //Write the content of the file to the server
int len;
while ((len = in.read(buffer)) != -1) {
    out.write(buffer, 0, len);
}

out.flush();
in.close();

Say, The file size is 101k, and I set the chunk size to be 4096.

  1. The HttpUrlConnection will send 4096 bytes to the server every write? and 1k for the last time?

  2. Note that I have used a 10k buffer to write to the outputstream, Does it matter that the chunk size and buffer size are not the same?

  3. If I disable the ChunkedStreamMode in my code, what's the effect compared to the code that I have set 4096?

1 Answers
Related