Bug 518569 - Use StandardCharset constants

Also: version bump for 4.11

Change-Id: I7055e6a2ceb521dbe6065888b735ac62caa73ef6
Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
index 171e368..bbaad79 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
@@ -29,6 +29,7 @@
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnmappableCharacterException;
 import java.nio.charset.UnsupportedCharsetException;
 
@@ -93,10 +94,6 @@
 	 * Constant for representing the error status. This is considered a value object.
 	 */
 	private static final IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.FileBuffer_status_error, null);
-	/**
-	 * Constant denoting UTF-8 encoding.
-	 */
-	private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
 
 	/**
 	 * Constant denoting an empty set of properties
@@ -297,7 +294,6 @@
 					return desc.getContentType();
 				return null;
 			}
-			
 		} catch (IOException x) {
 			throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.FileBuffer_error_queryContentDescription, fFileStore.toString()), x));
 		}
@@ -427,7 +423,7 @@
 			 * This is a workaround for a corresponding bug in Java readers and writer,
 			 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
 			 */
-			if (fHasBOM && CHARSET_UTF_8.equals(encoding))
+			if (fHasBOM && StandardCharsets.UTF_8.name().equals(encoding))
 				stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
 
 
@@ -451,7 +447,7 @@
 				 * This is a workaround for a corresponding bug in Java readers and writer,
 				 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
 				 */
-				if (fHasBOM && CHARSET_UTF_8.equals(encoding))
+				if (fHasBOM && StandardCharsets.UTF_8.name().equals(encoding))
 					out.write(IContentDescription.BOM_UTF_8);
 
 				out.write(bytes, 0, bytesLength);
@@ -524,7 +520,7 @@
 			 * This is a workaround for a corresponding bug in Java readers and writer,
 			 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
 			 */
-			if (hasBOM && CHARSET_UTF_8.equals(encoding)) {
+			if (hasBOM && StandardCharsets.UTF_8.name().equals(encoding)) {
 				int n= 0;
 				do {
 					int bytes= contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
index cc1fd6c..69a3e4d 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
@@ -27,6 +27,7 @@
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnmappableCharacterException;
 import java.nio.charset.UnsupportedCharsetException;
 
@@ -97,20 +98,6 @@
 	 * Constant for representing the error status. This is considered a value object.
 	 */
 	static final private IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.FileBuffer_status_error, null);
-	/**
-	 * Constant denoting UTF-8 encoding.
-	 */
-	private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
-	/**
-	 * Constant denoting UTF-16 encoding.
-	 * @since 3.4
-	 */
-	private static final String CHARSET_UTF_16= "UTF-16"; //$NON-NLS-1$
-	/**
-	 * Constant denoting UTF-16LE encoding.
-	 * @since 3.4
-	 */
-	private static final String CHARSET_UTF_16LE= "UTF-16LE"; //$NON-NLS-1$
 
 	/**
 	 * Constant denoting an empty set of properties
@@ -311,8 +298,8 @@
 
 		String encoding= computeEncoding();
 
-		if (fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16.equals(encoding))
-			encoding= CHARSET_UTF_16LE;
+		if (fBOM == IContentDescription.BOM_UTF_16LE && StandardCharsets.UTF_16.name().equals(encoding))
+			encoding= StandardCharsets.UTF_16LE.name();
 
 		Charset charset;
 		try {
@@ -355,10 +342,10 @@
 		 * This is a workaround for a corresponding bug in Java readers and writer,
 		 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
 		 */
-		if (fBOM == IContentDescription.BOM_UTF_8 && CHARSET_UTF_8.equals(encoding))
+		if (fBOM == IContentDescription.BOM_UTF_8 && StandardCharsets.UTF_8.name().equals(encoding))
 			stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
 
-		if (fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16LE.equals(encoding))
+		if (fBOM == IContentDescription.BOM_UTF_16LE && StandardCharsets.UTF_16LE.name().equals(encoding))
 			stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_16LE), stream);
 
 		if (fFile.exists()) {
@@ -513,7 +500,7 @@
 			 * This is a workaround for a corresponding bug in Java readers and writer,
 			 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
 			 */
-			if (fBOM != null && CHARSET_UTF_8.equals(encoding)) {
+			if (fBOM != null && StandardCharsets.UTF_8.name().equals(encoding)) {
 				int n= 0;
 				do {
 					int bytes= contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java
index 04e6af4..89943e6 100644
--- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java
+++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java
@@ -16,6 +16,7 @@
 import static org.junit.Assert.assertFalse;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import org.junit.After;
 import org.junit.Assert;
@@ -53,8 +54,7 @@
 		for (int i= 0; i < 500; i++) {
 			buf.append(TEST_CONTENT);
 		}
-		String encoding= "ISO-8859-1";
-		testForEncoding(buf, encoding);
+		testForEncoding(buf, StandardCharsets.ISO_8859_1.name());
 	}
 
 	@Test
@@ -63,8 +63,7 @@
 		for (int i= 0; i < 2000; i++) {
 			buf.append(TEST_CONTENT);
 		}
-		String encoding= "UTF-8";
-		testForEncoding(buf, encoding);
+		testForEncoding(buf, StandardCharsets.UTF_8.name());
 	}
 
 	@Test
@@ -73,8 +72,7 @@
 		for (int i= 0; i < FileCharSequenceProvider.BUFFER_SIZE * 2; i++) {
 			buf.append(TEST_CONTENT);
 		}
-		String encoding= "UTF-16";
-		testForEncoding(buf, encoding);
+		testForEncoding(buf, StandardCharsets.UTF_16.name());
 	}
 
 	private void testForEncoding(CharSequence buf, String encoding) throws CoreException, IOException {
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileCharSequenceProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileCharSequenceProvider.java
index cc8daff..080ac46 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileCharSequenceProvider.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileCharSequenceProvider.java
@@ -17,6 +17,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.eclipse.core.runtime.CoreException;
@@ -232,9 +233,6 @@
 	}
 
 	private final class FileCharSequence implements CharSequence {
-
-		private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
-
 		private Reader fReader;
 		private int fReaderPos;
 
@@ -277,7 +275,7 @@
 			boolean ok= false;
 			InputStream contents= fFile.getContents();
 			try {
-				if (CHARSET_UTF_8.equals(charset)) {
+				if (StandardCharsets.UTF_8.name().equals(charset)) {
 					/*
 					 * This is a workaround for a corresponding bug in Java readers and writer,
 					 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
diff --git a/org.eclipse.text/META-INF/MANIFEST.MF b/org.eclipse.text/META-INF/MANIFEST.MF
index e0240c6..f311cde 100644
--- a/org.eclipse.text/META-INF/MANIFEST.MF
+++ b/org.eclipse.text/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.text
-Bundle-Version: 3.8.0.qualifier
+Bundle-Version: 3.8.100.qualifier
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Export-Package: 
diff --git a/org.eclipse.text/pom.xml b/org.eclipse.text/pom.xml
index 0d88dcc..67dcf23 100644
--- a/org.eclipse.text/pom.xml
+++ b/org.eclipse.text/pom.xml
@@ -18,6 +18,6 @@
   </parent>
   <groupId>org.eclipse.text</groupId>
   <artifactId>org.eclipse.text</artifactId>
-  <version>3.8.0-SNAPSHOT</version>
+  <version>3.8.100-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/org.eclipse.text/src/org/eclipse/text/templates/TemplateReaderWriter.java b/org.eclipse.text/src/org/eclipse/text/templates/TemplateReaderWriter.java
index bb958c0..a0768f8 100644
--- a/org.eclipse.text/src/org/eclipse/text/templates/TemplateReaderWriter.java
+++ b/org.eclipse.text/src/org/eclipse/text/templates/TemplateReaderWriter.java
@@ -18,6 +18,7 @@
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -325,7 +326,7 @@
 
 			Transformer transformer=TransformerFactory.newInstance().newTransformer();
 			transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
-			transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+			transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
 			DOMSource source = new DOMSource(document);
 
 			transformer.transform(source, result);
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileDocumentProvider.java b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileDocumentProvider.java
index 2922335..c7351d7 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileDocumentProvider.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileDocumentProvider.java
@@ -25,6 +25,7 @@
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnmappableCharacterException;
 import java.nio.charset.UnsupportedCharsetException;
 
@@ -94,22 +95,6 @@
 	 * @since 2.1
 	 */
 	private static final QualifiedName ENCODING_KEY = new QualifiedName(EditorsUI.PLUGIN_ID, "encoding"); //$NON-NLS-1$
-	/**
-	 * Constant denoting UTF-8 encoding.
-	 * @since 3.0
-	 */
-	private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
-	/**
-	 * Constant denoting UTF-16 encoding.
-	 * @since 3.4
-	 */
-	private static final String CHARSET_UTF_16= "UTF-16"; //$NON-NLS-1$
-	/**
-	 * Constant denoting UTF-16LE encoding.
-	 * @since 3.4
-	 */
-	private static final String CHARSET_UTF_16LE= "UTF-16LE"; //$NON-NLS-1$
-
 
 	/**
 	 * The runnable context for that provider.
@@ -396,7 +381,7 @@
 			try (InputStream contentStream= file.getContents(false)) {
 				FileInfo info= (FileInfo)getElementInfo(editorInput);
 				boolean removeBOM= false;
-				if (CHARSET_UTF_8.equals(encoding)) {
+				if (StandardCharsets.UTF_8.name().equals(encoding)) {
 					if (info != null)
 						removeBOM= info.fBOM != null;
 					else
@@ -549,8 +534,8 @@
 			IFile file= input.getFile();
 			encoding= getCharsetForNewFile(file, document, info);
 
-			if (info != null && info.fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16.equals(encoding))
-				encoding= CHARSET_UTF_16LE;
+			if (info != null && info.fBOM == IContentDescription.BOM_UTF_16LE && StandardCharsets.UTF_16.name().equals(encoding))
+				encoding= StandardCharsets.UTF_16LE.name();
 
 			Charset charset;
 			try {
@@ -593,10 +578,10 @@
 			 * This is a workaround for a corresponding bug in Java readers and writer,
 			 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
 			 */
-			if (info != null && info.fBOM == IContentDescription.BOM_UTF_8 && CHARSET_UTF_8.equals(encoding))
+			if (info != null && info.fBOM == IContentDescription.BOM_UTF_8 && StandardCharsets.UTF_8.name().equals(encoding))
 				stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
 
-			if (info != null && info.fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16LE.equals(encoding))
+			if (info != null && info.fBOM == IContentDescription.BOM_UTF_16LE && StandardCharsets.UTF_16LE.name().equals(encoding))
 				stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_16LE), stream);
 
 			if (file.exists()) {
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java
index 605d4e4..d91aa42 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java
@@ -18,6 +18,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.charset.StandardCharsets;
 
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
@@ -416,7 +417,7 @@
 	 * 			- byte order mark is not valid for UTF-8
 	 */
 	private static boolean isUTF8BOM(String encoding, IStorage storage) throws CoreException {
-		if (storage instanceof IFile && "UTF-8".equals(encoding)) { //$NON-NLS-1$
+		if (storage instanceof IFile && StandardCharsets.UTF_8.name().equals(encoding)) { //$NON-NLS-1$
 			IFile file= (IFile) storage;
 			IContentDescription description= file.getContentDescription();
 			if (description != null) {
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java
index 30b35a6..bd8ee10 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java
@@ -18,6 +18,7 @@
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.Iterator;
 import java.util.List;
@@ -1679,7 +1680,7 @@
 		int returnCode= errorDialog.open();
 
 		if (returnCode == saveAsUTF8ButtonId) {
-			((IStorageDocumentProvider)documentProvider).setEncoding(getEditorInput(), "UTF-8"); //$NON-NLS-1$
+			((IStorageDocumentProvider) documentProvider).setEncoding(getEditorInput(), StandardCharsets.UTF_8.name());
 			IProgressMonitor monitor= getProgressMonitor();
 			try {
 				doSave(monitor);
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java
index 3e6589d..6cd6302 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java
@@ -14,6 +14,7 @@
 package org.eclipse.ui.genericeditor.tests;
 
 import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
 
 import org.junit.After;
 import org.junit.Before;
@@ -58,7 +59,7 @@
 		project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
 		project.create(null);
 		project.open(null);
-		project.setDefaultCharset("UTF-8", null);
+		project.setDefaultCharset(StandardCharsets.UTF_8.name(), null);
 		createAndOpenFile();
 	 }
 
@@ -75,8 +76,8 @@
 	 */
 	protected void createAndOpenFile(String name, String contents) throws Exception {
 		this.file = project.getFile(name);
-		this.file.create(new ByteArrayInputStream(contents.getBytes("UTF-8")), true, null);
-		this.file.setCharset("UTF-8", null);
+		this.file.create(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)), true, null);
+		this.file.setCharset(StandardCharsets.UTF_8.name(), null);
 		this.editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
 				.getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
 	}