[ 
https://issues.apache.org/jira/browse/HDDS-11860?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsz-wo Sze reassigned HDDS-11860:
---------------------------------

    Assignee: Tsz-wo Sze

> Improve BufferUtils.writeFully
> ------------------------------
>
>                 Key: HDDS-11860
>                 URL: https://issues.apache.org/jira/browse/HDDS-11860
>             Project: Apache Ozone
>          Issue Type: Improvement
>          Components: common
>    Affects Versions: 2.0.0
>            Reporter: Tsz-wo Sze
>            Assignee: Tsz-wo Sze
>            Priority: Major
>
> Address [review 
> comment|https://github.com/apache/ozone/pull/6652#discussion_r1854345430] 
> from HDDS-10821:
> bq. let's have another method to handle array?  The {{GatheringByteChannel}} 
> works more efficient in that way
> {code:java}
>   public static long writeFully(GatheringByteChannel ch, ByteBuffer[] 
> buffers) throws IOException {
>     long written = 0;
>     for(int i = 0; i < buffers.length; i++) {
>       while (buffers[i].remaining() > 0) {
>         final long n = ch.write(buffers, i, buffers.length - i);
>         if (n < 0) {
>           throw new IllegalStateException("GatheringByteChannel.write returns 
> " + n + " for " + ch);
>         }
>         written += n;
>       }
>     }
>     return written;
>   }
> {code}
> Also,
> bq. according to the javadoc, `n == 0` is a valid case.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to