docs: public Result isUTF16(byte[] buffer, boolean failOnNull) {
      if (buffer.length < 2) {
        return Result.INVALID;
      }
  
      int beAscii = 0;
      int beLines = 0;
      int leAscii = 0;
      int leLines = 0;
  
      for (int i = 0; i < buffer.length / 2; i++) {
        // using bytes is fine, since we will compare with positive numbers only
        byte c1 = buffer[i * 2];
        byte c2 = buffer[i * 2 + 1];
  
        if (c1 == 0) {
          if (c2 != 0) {
            if (c2 == 0x0a || c2 == 0x0d) {
              beLines++;
            }
            beAscii++;
          } else if (failOnNull) {
            // it's probably UTF-32 or binary
            return Result.INVALID;
          }
        } else if (c2 == 0) {
          leAscii++;
          if (c1 == 0x0a || c1 == 0x0d) {
            leLines++;
          }
        }
      }
  
      double beAsciiPerc = beAscii * 2.0 / (double) buffer.length;
      double leAsciiPerc = leAscii * 2.0 / (double) buffer.length;
  
      if (leLines == 0) {
        // could be BE
        if (beAsciiPerc >= UTF_16_NULL_PASS_THRESHOLD && leAsciiPerc < UTF_16_NULL_FAIL_THRESHOLD) {
          return Result.newValid(StandardCharsets.UTF_16BE);
        }
        if (beLines > 0) {
          // this gives FPs for UTF-32 if !failOnNull
          return Result.newValid(StandardCharsets.UTF_16BE);
        }
      } else if (beLines > 0) {
        // lines detected with both endiness -> can't be utf-16
        return Result.INVALID;
      }
      if (beLines == 0) {
        // could be BE
        if (leAsciiPerc >= UTF_16_NULL_PASS_THRESHOLD && beAsciiPerc < UTF_16_NULL_FAIL_THRESHOLD) {
          return Result.newValid(StandardCharsets.UTF_16LE);
        }
        if (leLines > 0) {
          // this gives FPs for UTF-32 if !failOnNull
          return Result.newValid(StandardCharsets.UTF_16LE);
        }
      }
  
      // if we reach here, means that there wasn't a line feed for a single endiness and we didn't see a strong null pattern for any of the
      // endiness.
      // It could happen if there are no line feeds in the text and it's a language that does not use ANSI (unicode > 255).
      return new Result(Validation.MAYBE, null);
    }