@@ -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 ();
@@ -369,7 +370,7 @@ static final class BoundedCapture extends ByteArrayOutputStream {
369370 private boolean frozen ;
370371
371372 BoundedCapture (int limit ) {
372- super (Math . min ( 8192 , limit ) );
373+ super (0 );
373374 this .limit = limit ;
374375 }
375376
@@ -380,8 +381,8 @@ public synchronized void write(byte[] bytes, int offset, int length) {
380381 int retained = Math .min (length , limit - count );
381382 int required = count + retained ;
382383 if (required > buf .length ) {
383- int doubled = (int ) Math .min (2L * buf .length , limit );
384- buf = Arrays .copyOf (buf , Math .max (required , doubled ));
384+ int growth = (int ) Math .min (limit , Math . max ( READ_BUFFER_BYTES , 2L * buf .length ) );
385+ buf = Arrays .copyOf (buf , Math .max (required , growth ));
385386 }
386387 super .write (bytes , offset , retained );
387388 truncated |= retained < length ;
@@ -410,7 +411,7 @@ private static final class Reader extends Thread {
410411 @ Override
411412 public void run () {
412413 try (InputStream stream = input ) {
413- byte [] buffer = new byte [8192 ];
414+ byte [] buffer = new byte [READ_BUFFER_BYTES ];
414415 int size ;
415416 while ((size = stream .read (buffer )) != -1 ) {
416417 capture .write (buffer , 0 , size );
0 commit comments