{"id":3019,"date":"2014-12-25T23:19:58","date_gmt":"2014-12-25T21:19:58","guid":{"rendered":"http:\/\/www.tutego.de\/blog\/javainsel\/?p=3019"},"modified":"2014-12-25T23:19:59","modified_gmt":"2014-12-25T21:19:59","slug":"endlich-transferto-im-inputstream","status":"publish","type":"post","link":"https:\/\/www.tutego.de\/blog\/javainsel\/2014\/12\/endlich-transferto-im-inputstream\/","title":{"rendered":"Endlich transferTo(&hellip;) im InputStream"},"content":{"rendered":"<p><a title=\"http:\/\/hg.openjdk.java.net\/jdk9\/jdk9\/jdk\/rev\/003295073abf\" href=\"http:\/\/hg.openjdk.java.net\/jdk9\/jdk9\/jdk\/rev\/003295073abf\">http:\/\/hg.openjdk.java.net\/jdk9\/jdk9\/jdk\/rev\/003295073abf<\/a> zeigt uns in Java 9 endlich eine lang erwartete Methode:<\/p>\n<pre>+    \/**\n+     * Reads all bytes from this input stream and writes the bytes to the\n+     * given output stream in the order that they are read. On return, this\n+     * input stream will be at end of stream. This method does not close either\n+     * stream.\n+     * &lt;p&gt;\n+     * This method may block indefinitely reading from the input stream, or\n+     * writing to the output stream. The behavior for the case where the input\n+     * and\/or output stream is &lt;i&gt;asynchronously closed&lt;\/i&gt;, or the thread\n+     * interrupted during the transfer, is highly input and output stream\n+     * specific, and therefore not specified.\n+     * &lt;p&gt;\n+     * If an I\/O error occurs reading from the input stream or writing to the\n+     * output stream, then it may do so after some bytes have been read or\n+     * written. Consequently the input stream may not be at end of stream and\n+     * one, or both, streams may be in an inconsistent state. It is strongly\n+     * recommended that both streams be promptly closed if an I\/O error occurs.\n+     *\n+     * @param  out the output stream, non-null\n+     * @return the number of bytes transferred\n+     * @throws IOException if an I\/O error occurs when reading or writing\n+     * @throws NullPointerException if {@code out} is {@code null}\n+     *\n+     * @since 1.9\n+     *\/\n+    public long transferTo(OutputStream out) throws IOException {\n+        Objects.requireNonNull(out, \"out\");\n+        long transferred = 0;\n+        byte[] buffer = new byte[TRANSFER_BUFFER_SIZE];\n+        int read;\n+        while ((read = this.read(buffer, 0, TRANSFER_BUFFER_SIZE)) &gt;= 0) {\n+            out.write(buffer, 0, read);\n+            transferred += read;\n+        }\n+        return transferred;\n+    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/hg.openjdk.java.net\/jdk9\/jdk9\/jdk\/rev\/003295073abf zeigt uns in Java 9 endlich eine lang erwartete Methode: + \/** + * Reads all bytes from this input stream and writes the bytes to the + * given output stream in the order that they are read. On return, this + * input stream will be at end of stream. This method [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[85],"tags":[],"class_list":["post-3019","post","type-post","status-publish","format-standard","hentry","category-java-9"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/3019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/comments?post=3019"}],"version-history":[{"count":1,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/3019\/revisions"}],"predecessor-version":[{"id":3020,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/3019\/revisions\/3020"}],"wp:attachment":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/media?parent=3019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/categories?post=3019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/tags?post=3019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}