@@ -746,6 +746,7 @@ public static String stringOf(Collection<?> source) {
746746 }
747747
748748 public static long remaining (ByteBuffer [] bufs ) {
749+ if (bufs == null ) return 0 ;
749750 long remain = 0 ;
750751 for (ByteBuffer buf : bufs ) {
751752 remain += buf .remaining ();
@@ -754,6 +755,7 @@ public static long remaining(ByteBuffer[] bufs) {
754755 }
755756
756757 public static boolean hasRemaining (List <ByteBuffer > bufs ) {
758+ if (bufs == null ) return false ;
757759 for (ByteBuffer buf : bufs ) {
758760 if (buf .hasRemaining ())
759761 return true ;
@@ -762,6 +764,7 @@ public static boolean hasRemaining(List<ByteBuffer> bufs) {
762764 }
763765
764766 public static boolean hasRemaining (ByteBuffer [] bufs ) {
767+ if (bufs == null ) return false ;
765768 for (ByteBuffer buf : bufs ) {
766769 if (buf .hasRemaining ())
767770 return true ;
@@ -770,6 +773,7 @@ public static boolean hasRemaining(ByteBuffer[] bufs) {
770773 }
771774
772775 public static long remaining (List <ByteBuffer > bufs ) {
776+ if (bufs == null ) return 0L ;
773777 long remain = 0 ;
774778 for (ByteBuffer buf : bufs ) {
775779 remain += buf .remaining ();
@@ -778,12 +782,14 @@ public static long remaining(List<ByteBuffer> bufs) {
778782 }
779783
780784 public static long synchronizedRemaining (List <ByteBuffer > bufs ) {
785+ if (bufs == null ) return 0L ;
781786 synchronized (bufs ) {
782787 return remaining (bufs );
783788 }
784789 }
785790
786- public static int remaining (List <ByteBuffer > bufs , int max ) {
791+ public static long remaining (List <ByteBuffer > bufs , long max ) {
792+ if (bufs == null ) return 0 ;
787793 long remain = 0 ;
788794 for (ByteBuffer buf : bufs ) {
789795 remain += buf .remaining ();
@@ -794,7 +800,13 @@ public static int remaining(List<ByteBuffer> bufs, int max) {
794800 return (int ) remain ;
795801 }
796802
797- public static int remaining (ByteBuffer [] refs , int max ) {
803+ public static int remaining (List <ByteBuffer > bufs , int max ) {
804+ // safe cast since max is an int
805+ return (int ) remaining (bufs , (long ) max );
806+ }
807+
808+ public static long remaining (ByteBuffer [] refs , long max ) {
809+ if (refs == null ) return 0 ;
798810 long remain = 0 ;
799811 for (ByteBuffer b : refs ) {
800812 remain += b .remaining ();
@@ -805,6 +817,11 @@ public static int remaining(ByteBuffer[] refs, int max) {
805817 return (int ) remain ;
806818 }
807819
820+ public static int remaining (ByteBuffer [] refs , int max ) {
821+ // safe cast since max is an int
822+ return (int ) remaining (refs , (long ) max );
823+ }
824+
808825 public static void close (Closeable ... closeables ) {
809826 for (Closeable c : closeables ) {
810827 try {
0 commit comments