diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 82e8def659c..b64b7572e44 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,10 @@ +2004-12-21 Alain Magloire + purpose: using charset from 'file' to encode in-memory String object into bytes + modifer: Wu Zhi Qiang + action: first get the charset from 'file', then use it + to encode the 'buffer.toString()' into bytes + * src/org/eclipse/cdt/internal/core/model/Util.java + 2004-12-09 Alain Magloire Fix for 80724: not showing initialized global variables. * utils/org/eclipse/cdt/utils/coff/parser/CygwinPEBinaryObject.java diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java index c51be2c15bf..2ffa08eb5df 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java @@ -111,11 +111,27 @@ public class Util implements ICLogConstants { public static void save(StringBuffer buffer, IFile file) throws CoreException { - byte[] bytes = buffer.toString().getBytes(); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - // use a platform operation to update the resource contents - boolean force = true; - file.setContents(stream, force, true, null); // record history + String encoding = null; + try { + encoding = file.getCharset(); + } catch (CoreException ce) { + // use no encoding + } + + byte[] bytes = null; + if (encoding != null) { + try { + bytes = buffer.toString().getBytes(encoding); + } catch (Exception e) { + } + } else { + bytes = buffer.toString().getBytes(); + } + + ByteArrayInputStream stream = new ByteArrayInputStream(bytes); + // use a platform operation to update the resource contents + boolean force = true; + file.setContents(stream, force, true, null); // record history } /**