[^ann] IDEA-86873 Out of memory exception when trying to manage file encodings

(cherry-picked from d9908e4)
This commit is contained in:
peter
2012-11-23 21:51:02 +01:00
parent 7212d8576f
commit 89424badf0
2 changed files with 4 additions and 4 deletions
@@ -29,6 +29,7 @@ import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.openapi.vfs.encoding.EncodingRegistry;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import com.intellij.psi.SingleRootFileViewProvider;
import com.intellij.util.io.IOUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -440,6 +441,9 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
charset = configured == null ? Charset.defaultCharset() : configured;
setCharset(charset);
}
else if (SingleRootFileViewProvider.isTooLargeForContentLoading(this)) {
charset = super.getCharset();
}
else {
try {
final byte[] content;
@@ -367,10 +367,6 @@ public class FileUtilRt {
@NotNull
public static byte[] loadBytes(@NotNull InputStream stream, int length) throws IOException {
if (isTooLarge(length)) {
throw new FileTooBigException("Too large file, size is " + length + " bytes.");
}
byte[] bytes = new byte[length];
int count = 0;
while (count < length) {