{"id":5193,"date":"2021-04-24T10:23:08","date_gmt":"2021-04-24T02:23:08","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=5193"},"modified":"2021-04-24T10:23:08","modified_gmt":"2021-04-24T02:23:08","slug":"%e8%a7%a3%e5%86%b3java%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e4%b8%8b%e8%bd%bd%e5%9b%be%e7%89%87%e8%b5%84%e6%ba%90%e8%bf%bd%e5%8a%a0byte%ef%bc%8c%e5%af%bc%e8%87%b4%e5%9b%be%e7%89%87%e7%ad%89%e6%96%87","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=5193","title":{"rendered":"\u89e3\u51b3Java\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u56fe\u7247(\u8d44\u6e90)\u8ffd\u52a0byte\uff0c\u5bfc\u81f4\u56fe\u7247\u7b49\u6587\u6863\u53ea\u663e\u793a\u4e00\u534a\u95ee\u9898"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u8fd9\u7bc7\u6587\u7ae0\u60f3\u4e86\u5f88\u4e45\uff0c\u6ca1\u60f3\u5230\u5408\u9002\u7684\u6807\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u5916\u672c\u6587\u8bb2\u7684\u4e0d\u662f\u9ad8\u6df1\u83ab\u6d4b\u7684\u6280\u672f\uff0c\u800c\u662f\u5728\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u5ffd\u89c6\u7684\u7f16\u7801\u7ec6\u8282\u5bfc\u81f4\u7684\u7a0b\u5e8f bug\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5927\u578b\u590d\u6742\u7684\u7a0b\u5e8f\u6216\u5206\u5e03\u5f0f\u7cfb\u7edf\u53ef\u80fd\u90fd\u5b58\u5728\u4e00\u4e2a\u4e13\u95e8\u7684\u670d\u52a1\u6765\u63d0\u4f9b\u6587\u4ef6\u7684\u4e0a\u4f20\u548c\u4e0b\u8f7d\uff0c\u800c\u4e00\u4e2a to B \u7684\u4ea7\u54c1\uff0c\u8fd8\u8981\u5728\u81ea\u6709\u7684\u4ea7\u54c1\u529f\u80fd\u57fa\u7840\u4e0a\u53bb\u9002\u914d\u7b2c\u4e09\u65b9\u7684\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u6b64\uff0c\u6211\u4eec\u5185\u90e8\u7684\u6587\u4ef6\u670d\u52a1\uff0c\u76ee\u524d\u652f\u6301 fastdfs\uff0cminio\uff0c\u963f\u91cc\u4e91 oss\uff0c\u817e\u8baf\u4e91 cos \u7b49\u529f\u80fd\u3002\u8fd9\u6837\u4e00\u4e2a\u6587\u4ef6\u7684\u4e0a\u4f20\u548c\u4e0b\u8f7d\u5c31\u9700\u8981\u4e00\u9053\u4e2d\u8f6c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c\u6211\u7684\u540c\u4e8b\uff0c\u5728\u4e2d\u8f6c\u6587\u4ef6\u65f6\uff0c\u4ea7\u751f\u4e86 bug\uff0c\u5bfc\u81f4\u5728\u9884\u89c8\u4e0b\u8f7d\u56fe\u7247\u65f6\uff0c\u56fe\u7247\u611f\u89c9\u88ab\u622a\u53d6\u4e86\uff0c\u53ea\u5269\u4e00\u534a\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u6211\u8d34\u4e00\u4e0b\u9519\u8bef\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>OutputStream out = response.getOutputStream();\nDataOutputStream dos = new DataOutputStream(out);\nbyte[] buf = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = stream.read(buf, 0, buf.length)) &gt;= 0) {\n    dos.write(buf);\n}\ndos.flush();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u4e2d\u7684 dos.write(buf); \u7528\u6cd5\u6709\u8bef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bd4\u5982\uff0c\u6211\u6700\u540e\u4e00\u6b21\u53ea\u8bfb\u53d6\u5230\u4e86 512 \u4e2a byte \u6570\u636e\u3002buf \u6570\u7ec4\u7684\u957f\u5ea6\u4e00\u5171\u662f 1024\uff0c\u540e\u9762\u6709 512 \u4e2a\u662f\u6ca1\u7528\u7684\u3002\u8fd9\u91cc\u76f4\u63a5\u8c03\u7528 dos.write(buf); \u5c31\u4f1a\u591a\u5199\u5165 512 \u4e2a\u65e0\u7528\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7ec8\u5c31\u4f1a\u5bfc\u81f4\u56fe\u7247\u7684\u90e8\u5206\u5185\u5bb9\u201c\u4e22\u5931\u201d\uff0c\u6216\u663e\u793a\u6210\u7070\u8272\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/buf-write.png\" alt=\"\" \/><figcaption>\u56fe\u7247\u663e\u793a\u4e00\u534a\u793a\u4f8b<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7ec8\u5b8c\u6574\u6b63\u786e\u7684\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>OutputStream out = response.getOutputStream();\nDataOutputStream dos = new DataOutputStream(out);\nbyte[] buf = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = stream.read(buf, 0, buf.length)) &gt;= 0) {\n    \/\/\u5e76\u4e0d\u662f\u6bcf\u6b21\u90fd\u80fd\u8bfb\u52301024\u4e2a\u5b57\u8282\uff0c\u6240\u6709\u7528bytesRead\u4f5c\u4e3a\u6bcf\u6b21\u8bfb\u53d6\u6570\u636e\u7684\u957f\u5ea6\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u6587\u4ef6\u635f\u574f\u7684\u9519\u8bef\n    out.write(buf, 0, bytesRead);\n}\ndos.flush();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\uff0c\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u5230\u66f4\u591a\u4eba\uff0c\u907f\u514d\u8df3\u5751\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=5193\">\u89e3\u51b3Java\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u56fe\u7247(\u8d44\u6e90)\u8ffd\u52a0byte\uff0c\u5bfc\u81f4\u56fe\u7247\u7b49\u6587\u6863\u53ea\u663e\u793a\u4e00\u534a\u95ee\u9898<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u60f3\u4e86\u5f88\u4e45\uff0c\u6ca1\u60f3\u5230\u5408\u9002\u7684\u6807\u9898\u3002 \u53e6\u5916\u672c\u6587\u8bb2\u7684\u4e0d\u662f\u9ad8\u6df1\u83ab\u6d4b\u7684\u6280\u672f\uff0c\u800c\u662f\u5728\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u5ffd\u89c6\u7684\u7f16\u7801 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[251,356,517,1172,903],"class_list":["post-5193","post","type-post","status-publish","format-standard","hentry","category-java","tag-251","tag-356","tag-517","tag-1172","tag-903"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5193"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5193\/revisions"}],"predecessor-version":[{"id":5194,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5193\/revisions\/5194"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}