Bug 559501 - Use charset from IFile in TextFileSnapshot
diff --git a/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshot.java b/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshot.java
index cb38067..a4a4c9a 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshot.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshot.java
@@ -13,6 +13,7 @@
 package org.eclipse.handly.snapshot;
 
 import java.net.URI;
+import java.nio.charset.Charset;
 
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileStore;
@@ -95,7 +96,17 @@
                 Activator.logError(e);
                 return NON_EXISTING;
             }
-            return new TextFileStoreSnapshot(fileStore);
+            Charset charset = null;
+            try
+            {
+                charset = Charset.forName(TextFileSnapshotWs.getCharset(file));
+            }
+            catch (Exception e)
+            {
+                Activator.logError(e);
+            }
+            return charset == null ? new TextFileStoreSnapshot(fileStore)
+                : new TextFileStoreSnapshot(fileStore, charset);
         }
         return new TextFileSnapshotWs(file);
     }
diff --git a/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshotWs.java b/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshotWs.java
index ca451c7..8f49827 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshotWs.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/snapshot/TextFileSnapshotWs.java
@@ -125,10 +125,13 @@
 
     private void cacheCharset() throws CoreException
     {
-        if (charset != null)
-            return;
+        if (charset == null)
+            charset = getCharset(file);
+    }
 
-        charset = file.getCharset(false);
+    static String getCharset(IFile file) throws CoreException
+    {
+        String charset = file.getCharset(false);
         if (charset == null)
         {
             try (InputStream contents = file.getContents(false))
@@ -143,6 +146,7 @@
         }
         if (charset == null)
             charset = file.getParent().getDefaultCharset();
+        return charset;
     }
 
     private String readContents() throws CoreException