Skip to content

Commit

Permalink
处理下载大文件时OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
VeiZhang committed Sep 26, 2022
1 parent 9953b7f commit 1a7fd0d
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class HttpUtil
{
private static final String TAG = HttpUtil.class.getSimpleName();

private static final int STREAM_LEN = 8 * 1024;

/**
* 转换链接中中文字符
*
Expand Down Expand Up @@ -132,6 +134,11 @@ public static void setConnectParam(HttpURLConnection conn, String url) throws Ex
// 检查浏览页面的访问者在用什么操作系统(包括版本号)浏览器(包括版本号)和用户个人偏好
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
conn.setRequestProperty("Connection", "Keep-Alive");

/**
* 内部缓冲区,防止超大文件导致OOM
*/
conn.setChunkedStreamingMode(STREAM_LEN);
}

/**
Expand Down

0 comments on commit 1a7fd0d

Please sign in to comment.