You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Attila Doroszlai (Jira)" <ji...@apache.org> on 2024/12/14 07:46:00 UTC
[jira] [Resolved] (HDDS-11860) Improve BufferUtils.writeFully
[ https://issues.apache.org/jira/browse/HDDS-11860?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Attila Doroszlai resolved HDDS-11860.
-------------------------------------
Fix Version/s: 2.0.0
Resolution: Implemented
> 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
> Labels: pull-request-available
> Fix For: 2.0.0
>
>
> 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: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org