code: private void throttledTransfer(MockResponse throttlePolicy, InputStream in, OutputStream out,
              long limit) throws IOException {
          byte[] buffer = new byte[1024];
          int bytesPerPeriod = throttlePolicy.getThrottleBytesPerPeriod();
          long delayMs = throttlePolicy.getThrottleUnit().toMillis(throttlePolicy.getThrottlePeriod());
  
          while (true) {
              for (int b = 0; b < bytesPerPeriod; ) {
                  int toRead = (int) Math.min(Math.min(buffer.length, limit), bytesPerPeriod - b);
                  int read = in.read(buffer, 0, toRead);
                  if (read == -1) return;
  
                  out.write(buffer, 0, read);
                  out.flush();
                  b += read;
                  limit -= read;
  
                  if (limit == 0) return;
              }
  
              try {
                  if (delayMs != 0) Thread.sleep(delayMs);
              } catch (InterruptedException e) {
                  throw new AssertionError();
              }
          }
      }
docs: Transfer bytes from {@code in} to {@code out} until either {@code length}
  bytes have been transferred or {@code in} is exhausted. The transfer is
  throttled according to {@code throttlePolicy}.