private static byte[] readStreamFully(@NotNull ImageInputStream stream) throws IOException {
      if (stream.length() != -1) {
        byte[] bytes = new byte[(int)stream.length()];  // Integer overflow prevented by canDecode check in reader spi above.
        stream.readFully(bytes);
        return bytes;
      }

      // Unknown file size
      ByteArrayOutputStream buffer = new ByteArrayOutputStream(0x100000);  // initialize with 1 MiB to minimize reallocation.
      final int bufferSize = 0x4000;    // 16k
      byte[] bytes = new byte[bufferSize];
      int idx;
      for (idx = 0; idx < MAX_FILE_SIZE / bufferSize; idx++) {  // Just to make sure we don't exceed MAX_FILE_SIZE
        int read = stream.read(bytes, 0, bufferSize);
        buffer.write(bytes, 0, read);
        if (read != bufferSize) {
          break;
        }
      }
      if (idx == MAX_FILE_SIZE / bufferSize) {
        throw new IOException("webp image too large");
      }
      return buffer.toByteArray();
    }
private static byte[] readStreamFully(@NotNull ImageInputStream stream)