@@ -44,6 +44,7 @@ interface WatchdogFactory {
4444 public static final long WAIT_GRACE_MILLIS = 5_000L ;
4545 public static final int DEFAULT_STDOUT_LIMIT = 8 * 1024 * 1024 ;
4646 public static final int DEFAULT_STDERR_LIMIT = 2 * 1024 * 1024 ;
47+ private static final int READ_BUFFER_BYTES = 8192 ;
4748 private static final long POLL_NANOS = TimeUnit .MILLISECONDS .toNanos (10L );
4849 private static final int DEFAULT_MAX_CONCURRENT = Math .max (2 , java .lang .Runtime .getRuntime ().availableProcessors ());
4950 private static final Object LEGACY_LOCK = new Object ();
@@ -376,7 +377,7 @@ static final class BoundedCapture extends ByteArrayOutputStream {
376377 private boolean frozen ;
377378
378379 BoundedCapture (int limit ) {
379- super (Math . min ( 8192 , limit ) );
380+ super (0 );
380381 this .limit = limit ;
381382 }
382383
@@ -387,8 +388,8 @@ public synchronized void write(byte[] bytes, int offset, int length) {
387388 int retained = Math .min (length , limit - count );
388389 int required = count + retained ;
389390 if (required > buf .length ) {
390- int doubled = (int ) Math .min (2L * buf .length , limit );
391- buf = Arrays .copyOf (buf , Math .max (required , doubled ));
391+ int growth = (int ) Math .min (limit , Math . max ( READ_BUFFER_BYTES , 2L * buf .length ) );
392+ buf = Arrays .copyOf (buf , Math .max (required , growth ));
392393 }
393394 super .write (bytes , offset , retained );
394395 truncated |= retained < length ;
@@ -417,7 +418,7 @@ private static final class Reader extends Thread {
417418 @ Override
418419 public void run () {
419420 try (InputStream stream = input ) {
420- byte [] buffer = new byte [8192 ];
421+ byte [] buffer = new byte [READ_BUFFER_BYTES ];
421422 int size ;
422423 while ((size = stream .read (buffer )) != -1 ) {
423424 capture .write (buffer , 0 , size );
0 commit comments