gpt4 book ai didi

android - Android HttpURLConnection.setChunkedStreamingMode() 的默认 block 长度?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:49:30 26 4
gpt4 key购买 nike

HttpURLConnection.setChunkedStreamingMode() 的文档中,它说如果我在参数中指定0,它将使用默认的 block 长度,例如:

conn.setChunkedStreamingMode(0);

默认 block 长度的确切值是多少?参数的单位是什么?以字节为单位?

最佳答案

你的问题让我很好奇,所以我测试了一些东西。

默认 block 长度的确切值是多少?

我找到了 here那个 chunkLength 是一个 protected variable HttpURLConnection 类的,这意味着它只能在类本身或子类中访问。所以我创建了 HttpURLConnection 的子类并尝试打印出 chunkLength

class HttpTest extends HttpURLConnection {

protected HttpTest(URL url) {
super(url);
Log.d("CHUNKLENGTH", String.format("%d", this.chunkLength));
this.setChunkedStreamingMode(0);
Log.d("CHUNKLENGTH", String.format("%d", this.chunkLength));
}

@Override
public void disconnect() {
// TODO Auto-generated method stub
}

@Override
public boolean usingProxy() {
// TODO Auto-generated method stub
return false;
}

@Override
public void connect() throws IOException {
// TODO Auto-generated method stub

}
}

这样调用

try {
HttpTest test = new HttpTest(new URL("http://www.google.com/"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

结果是这样

enter image description here

由此,我们可以得出结论,它使用的默认值为 1024


参数的单位是什么?

在您发布的链接中,提到

A small chunk length increases the number of bytes that must be transmitted because of the header on every chunk.

我认为假设您必须给出字节数是安全的。默认的 1024 也符合该标准

关于android - Android HttpURLConnection.setChunkedStreamingMode() 的默认 block 长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26730205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com