文件下载分chunk写

文件下载

final OutputStream output = response.getOutputStream();
byte[] data = ...
output.write(data);

分chunk下载

public static void writeChunked(final byte[] data, final OutputStream output)
            throws IOException {
        if (data != null) {
            int bytes = data.length;
            int offset = 0;
            while (bytes > 0) {
                int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
                output.write(data, offset, chunk);
                bytes -= chunk;
                offset += chunk;
            }
        }
    }

想获取最新内容,请关注微信公众号

文件下载分chunk写_第1张图片
qrcode_for_gh_121b87c80448_258.jpg

你可能感兴趣的:(文件下载分chunk写)