EA-97992 - assert: VirtualFile.setBinaryContent

This commit is contained in:
Dmitry Batrak
2017-03-01 18:24:40 +03:00
parent a0cae94e87
commit ca23ee2ef6
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,10 @@ package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
@@ -62,7 +63,13 @@ public class RemoveBomAction extends AnAction implements DumbAware {
byte[] bytes = file.contentsToByteArray();
byte[] contentWithStrippedBom = new byte[bytes.length - bom.length];
System.arraycopy(bytes, bom.length, contentWithStrippedBom, 0, contentWithStrippedBom.length);
file.setBinaryContent(contentWithStrippedBom);
ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Void, IOException>() {
@Override
public Void compute() throws IOException {
file.setBinaryContent(contentWithStrippedBom);
return null;
}
});
}
catch (IOException ex) {
LOG.warn("Unexpected exception occurred on attempt to remove BOM from file " + file, ex);