1 12 package org.eclipse.jdt.apt.core.internal.env; 13 14 import java.io.IOException ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IWorkspace; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IStatus; 21 22 25 public class EncodedFileOutputStream extends BinaryFileOutputStream { 26 27 private final String _charsetName; 28 29 public EncodedFileOutputStream(IFile file, BuildEnv env, String charsetName) { 30 super(file, env); 31 _charsetName = charsetName; 32 } 33 34 @Override 35 public void close() throws IOException { 36 super.close(); 37 if (_charsetName != null) { 38 39 IWorkspace ws = ResourcesPlugin.getWorkspace(); 42 43 IFile resourceFile = _file.getProject().getFile(".settings/org.eclipse.core.resources.prefs"); IStatus result = ws.validateEdit(new IFile[]{resourceFile}, IWorkspace.VALIDATE_PROMPT); 46 if (result.getSeverity() == IStatus.CANCEL) { 47 return; 49 } 50 try { 51 _file.setCharset(_charsetName, null); 52 } 53 catch (CoreException ce) { 54 IOException ioe = new IOException ("Could not set charset: " + _charsetName); ioe.initCause(ce); 56 throw ioe; 57 } 58 } 59 } 60 } 61 | Popular Tags |