public static Charset guessEncoding(@NotNull File f, int bufferLength, @NotNull Charset defaultCharset) throws IOException {
    if (bufferLength == 0) {
      throw new IllegalArgumentException("Can't analyze empty buffer");
    }
    byte[] buffer = new byte[bufferLength];
    int read;
    try (FileInputStream fis = new FileInputStream(f)) {
      read = fis.read(buffer);
    }
    CharsetToolkit toolkit = new CharsetToolkit(buffer, defaultCharset, false);
    return toolkit.guessEncoding(read);
  }
public static Charset guessEncoding(@NotNull File f, int bufferLength, @NotNull Charset defaultCharset)