use of java.nio.charset.Charset in project intellij-community by JetBrains.
the class CreatePatchConfigurationPanel method initEncodingCombo.
private void initEncodingCombo() {
final DefaultComboBoxModel<Charset> encodingsModel = new DefaultComboBoxModel<>(CharsetToolkit.getAvailableCharsets());
myEncoding.setModel(encodingsModel);
Charset projectCharset = EncodingProjectManager.getInstance(myProject).getDefaultCharset();
myEncoding.setSelectedItem(projectCharset);
}
use of java.nio.charset.Charset in project intellij-community by JetBrains.
the class EncodingManager method applySettings.
private void applySettings(VirtualFile file) {
if (file == null)
return;
if (!Utils.isEnabled(CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings()))
return;
// Prevent "setEncoding" calling "saveAll" from causing an endless loop
isApplyingSettings = true;
try {
final String filePath = Utils.getFilePath(myProject, file);
final List<OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(myProject, filePath);
final EncodingProjectManager encodingProjectManager = EncodingProjectManager.getInstance(myProject);
final String charset = Utils.configValueForKey(outPairs, charsetKey);
if (!charset.isEmpty()) {
final Charset newCharset = encodingMap.get(charset);
if (newCharset != null) {
if (Comparing.equal(newCharset, file.getCharset()))
return;
encodingProjectManager.setEncoding(file, newCharset);
} else {
Utils.invalidConfigMessage(myProject, charset, charsetKey, filePath);
}
}
} finally {
isApplyingSettings = false;
}
}
use of java.nio.charset.Charset in project intellij-community by JetBrains.
the class VirtualFile method getCharset.
/**
* @return Retrieve the charset file has been loaded with (if loaded) and would be saved with (if would).
*/
@NotNull
public Charset getCharset() {
Charset charset = getStoredCharset();
if (charset == null) {
charset = EncodingRegistry.getInstance().getDefaultCharset();
setCharset(charset);
}
return charset;
}
use of java.nio.charset.Charset in project intellij-community by JetBrains.
the class LightVirtualFile method contentsToByteArray.
@Override
@NotNull
public byte[] contentsToByteArray() throws IOException {
final Charset charset = getCharset();
final String s = getContent().toString();
return s.getBytes(charset.name());
}
use of java.nio.charset.Charset in project intellij-community by JetBrains.
the class ExternalDiffToolUtil method createTempFile.
@NotNull
private static File createTempFile(@NotNull final DocumentContent content, @NotNull FileNameInfo fileName) throws IOException {
FileDocumentManager.getInstance().saveDocument(content.getDocument());
LineSeparator separator = content.getLineSeparator();
if (separator == null)
separator = LineSeparator.getSystemLineSeparator();
Charset charset = content.getCharset();
if (charset == null)
charset = Charset.defaultCharset();
Boolean hasBom = content.hasBom();
if (hasBom == null)
hasBom = CharsetToolkit.getMandatoryBom(charset) != null;
String contentData = ReadAction.compute(() -> {
return content.getDocument().getText();
});
if (separator != LineSeparator.LF) {
contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString());
}
byte[] bytes = contentData.getBytes(charset);
byte[] bom = hasBom ? CharsetToolkit.getPossibleBom(charset) : null;
if (bom != null) {
bytes = ArrayUtil.mergeArrays(bom, bytes);
}
return createFile(bytes, fileName);
}
Aggregations