Skip to content

Commit

Permalink
8334028
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuch committed Jun 11, 2024
1 parent aaaa86b commit 0fae740
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -356,6 +356,7 @@ public void onNext(List<ByteBuffer> items) {
// incoming buffers are allocated by http client internally,
// and won't be used anywhere except this place.
// So it's free simply to store them for further processing.
Objects.requireNonNull(items); // ensure NPE is thrown before assert
assert Utils.hasRemaining(items);
received.addAll(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ public static String stringOf(Collection<?> source) {
}

public static long remaining(ByteBuffer[] bufs) {
if (bufs == null) return 0;
long remain = 0;
for (ByteBuffer buf : bufs) {
remain += buf.remaining();
Expand All @@ -754,6 +755,7 @@ public static long remaining(ByteBuffer[] bufs) {
}

public static boolean hasRemaining(List<ByteBuffer> bufs) {
if (bufs == null) return false;
for (ByteBuffer buf : bufs) {
if (buf.hasRemaining())
return true;
Expand All @@ -762,6 +764,7 @@ public static boolean hasRemaining(List<ByteBuffer> bufs) {
}

public static boolean hasRemaining(ByteBuffer[] bufs) {
if (bufs == null) return false;
for (ByteBuffer buf : bufs) {
if (buf.hasRemaining())
return true;
Expand All @@ -770,6 +773,7 @@ public static boolean hasRemaining(ByteBuffer[] bufs) {
}

public static long remaining(List<ByteBuffer> bufs) {
if (bufs == null) return 0L;
long remain = 0;
for (ByteBuffer buf : bufs) {
remain += buf.remaining();
Expand All @@ -778,12 +782,14 @@ public static long remaining(List<ByteBuffer> bufs) {
}

public static long synchronizedRemaining(List<ByteBuffer> bufs) {
if (bufs == null) return 0L;
synchronized (bufs) {
return remaining(bufs);
}
}

public static int remaining(List<ByteBuffer> bufs, int max) {
public static long remaining(List<ByteBuffer> bufs, long max) {
if (bufs == null) return 0;
long remain = 0;
for (ByteBuffer buf : bufs) {
remain += buf.remaining();
Expand All @@ -794,7 +800,13 @@ public static int remaining(List<ByteBuffer> bufs, int max) {
return (int) remain;
}

public static int remaining(ByteBuffer[] refs, int max) {
public static int remaining(List<ByteBuffer> bufs, int max) {
// safe cast since max is an int
return (int) remaining(bufs, (long) max);
}

public static long remaining(ByteBuffer[] refs, long max) {
if (refs == null) return 0;
long remain = 0;
for (ByteBuffer b : refs) {
remain += b.remaining();
Expand All @@ -805,6 +817,11 @@ public static int remaining(ByteBuffer[] refs, int max) {
return (int) remain;
}

public static int remaining(ByteBuffer[] refs, int max) {
// safe cast since max is an int
return (int) remaining(refs, (long) max);
}

public static void close(Closeable... closeables) {
for (Closeable c : closeables) {
try {
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/java/net/httpclient/BodySubscribersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/*
* @test
* @summary Basic test for the standard BodySubscribers default behavior
* @bug 8225583
* @bug 8225583 8334028
* @run testng BodySubscribersTest
*/

Expand Down

0 comments on commit 0fae740

Please sign in to comment.