szetszwo commented on code in PR #6652:
URL: https://github.com/apache/ozone/pull/6652#discussion_r1854345430


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/utils/BufferUtils.java:
##########
@@ -136,4 +139,19 @@ public static int getNumberOfBins(long numElements, int 
maxElementsPerBin) {
     }
     return Math.toIntExact(n);
   }
+
+  /**
+   * Write all remaining bytes in buffer to the given channel.
+   */
+  public static long writeFully(GatheringByteChannel ch, ByteBuffer bb) throws 
IOException {
+    long written = 0;
+    while (bb.remaining() > 0) {
+      int n = ch.write(bb);
+      if (n <= 0) {

Review Comment:
   According to the javadoc, `n == 0` is a valid case.
   
   BTW, let's have another method to handle array?  The `GatheringByteChannel` 
works more efficient in that way.
   ```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;
     }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to