/**
   * Update the encoding information in private member variables.
   *
   * @return true if the encoding information is updated.
   */
  private boolean updateEncodingInfoPrivately() {
    // Get the updated encoding setting.
    String encoding = getEncoding();

    // Do detection.
    CharsetMatch[] detected_encodings = null;
    int encoding_confidence = 0;

    if (text_file_store != null) {
      try {
        detected_encodings =
            EncodingUtil.detectCharsets(text_file_store.openInputStream(EFS.NONE, null));
        encoding_confidence = EncodingUtil.getConfidence(detected_encodings, encoding);

        // Check whether the text file can really be decoded by the encoding, and adjust the
        // confidence.
        boolean is_text_file_decodable =
            EncodingUtil.isDecodable(text_file_store.openInputStream(EFS.NONE, null), encoding);
        if (!is_text_file_decodable) {
          // CharsetDetector may not read all the input data, so the confidence may not be zero even
          // if the text cannot be decoded.
          encoding_confidence = 0;
        } else if (encoding_confidence == 0) {
          // CharsetDetector does not support all encodings, so the confidence may be zero even if
          // the text can be decoded.
          encoding_confidence = 1;
        }
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    this.detected_encodings = detected_encodings;
    this.encoding_confidence = encoding_confidence;

    // Just assume that the encoding information is updated.
    return true;
  }
 /** Trims any white space and converts into Latin-1 from UTF-8. */
 public static String clean(final String string) {
   return string == null ? null : EncodingUtil.convertToKindleSafe(string).trim();
 }
 @Override
 protected boolean isValueEditableForFile(final VirtualFile virtualFile) {
   return virtualFile == null
       || virtualFile.isDirectory()
       || EncodingUtil.checkSomeActionEnabled(virtualFile) == null;
 }