@Override public String getCharsetFor(Reader contents) throws CoreException { String charset; ResourceInfo info = getResourceInfo(false, false); int flags = getFlags(info); if (exists(flags, true)) // the file exists, look for user setting if ((charset = workspace.getCharsetManager().getCharsetFor(getFullPath(), false)) != null) // if there is a file-specific user setting, use it return charset; // tries to obtain a description from the contents provided IContentDescription description; try { // TODO need to take project specific settings into account IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); description = contentTypeManager.getDescriptionFor( contents, getName(), new QualifiedName[] {IContentDescription.CHARSET}); } catch (IOException e) { String message = NLS.bind(Messages.resources_errorContentDescription, getFullPath()); throw new ResourceException( IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e); } if (description != null) if ((charset = description.getCharset()) != null) // the description contained charset info, we are done return charset; // could not find out the encoding based on the contents... default to parent's return workspace.getCharsetManager().getCharsetFor(getFullPath().removeLastSegments(1), true); }