{"id":2239,"date":"2023-02-17T11:39:02","date_gmt":"2023-02-17T03:39:02","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=2239"},"modified":"2023-10-31T15:41:34","modified_gmt":"2023-10-31T07:41:34","slug":"java-download-file-without-saving","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=2239","title":{"rendered":"[Java] Download file without saving"},"content":{"rendered":"<p>Source:<\/p>\n<p><a href=\"https:\/\/blog.csdn.net\/jilindaxue\/article\/details\/76615301\">CSDN: InputStream\u7c7bavailable\u548cread\u65b9\u6cd5\u53ef\u80fd\u8bfb\u53d6\u4e0d\u5230\u5b8c\u6574\u7684\u6d41\u6570\u636e<\/a><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/34895339\/how-to-read-a-http-file-inmemory-without-saving-on-local-drive\">stackoverflow: How to read a http file inmemory without saving on local drive?<\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">private static InputStream download(String sourceURL) throws Exception {\n        InputStream inputStream = new URL(sourceURL).openStream();\n        ByteArrayOutputStream output = new ByteArrayOutputStream();\n        byte[] buffer = new byte[4096];\n        int n = 0;\n        while (-1 != (n = inputStream.read(buffer))) {\n            output.write(buffer, 0, n);\n        }\n        return new ByteArrayInputStream(output.toByteArray());\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Source: CSDN: InputStream\u7c7bavailable\u548cread\u65b9\u6cd5\u53ef\u80fd\u8bfb\u53d6\u4e0d\u5230\u5b8c\u6574\u7684\u6d41\u6570\u636e stackoverflow: How to read a http file inmemory without saving on local drive? private static InputStream download(String sourceURL) throws Exception { InputStream inputStream = new URL(sourceURL).openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=2239\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-2239","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2239"}],"version-history":[{"count":2,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2239\/revisions"}],"predecessor-version":[{"id":2241,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2239\/revisions\/2241"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}