class UnicodeBom {

  public static String toString(byte[] input) {
    if (input.length >= 3 && input[0] == X_EF && input[1] == X_BB && input[2] == X_BF) {
      return new String(input, 3, input.length - 3, StandardCharsets.UTF_8);

    } else if (input.length >= 2 && input[0] == X_FE && input[1] == X_FF) {
      return new String(input, 2, input.length - 2, StandardCharsets.UTF_16BE);

    } else if (input.length >= 2 && input[0] == X_FF && input[1] == X_FE) {
      return new String(input, 2, input.length - 2, StandardCharsets.UTF_16LE);

    } else {
      return new String(input, StandardCharsets.UTF_8);
    }
  }

  private  UnicodeBom();

}