Bug 518566 - Use StandardCharsets 

Simpler code and additional security against typos.

Change-Id: Ia6c55ebaae59db4dbdedbed4c58c166cc773644f
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java
index 1bd5e6e..ef47cc2 100644
--- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java
+++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -12,8 +12,8 @@
 package org.eclipse.core.internal.filesystem.local.unix;
 
 import java.io.File;
-import java.io.UnsupportedEncodingException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.Enumeration;
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileInfo;
@@ -168,12 +168,7 @@
 	public static int getFlag(String flag) {
 		if (!usingNatives)
 			return -1;
-		try {
-			return getflag(flag.getBytes("ASCII")); //$NON-NLS-1$
-		} catch (UnsupportedEncodingException e) {
-			// Should never happen
-			return -1;
-		}
+		return getflag(flag.getBytes(StandardCharsets.US_ASCII));
 	}
 
 	private static byte[] fileNameToBytes(String fileName) {
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/MarkerInfo.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/MarkerInfo.java
index d0d2718..5b4b1ae 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/MarkerInfo.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/MarkerInfo.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -13,7 +13,7 @@
  *******************************************************************************/
 package org.eclipse.core.internal.resources;
 
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.eclipse.core.internal.utils.*;
@@ -54,13 +54,7 @@
 			//optimized test based on maximum 3 bytes per character
 			if (valueString.length() < 21000)
 				return value;
-			byte[] bytes;
-			try {
-				bytes = valueString.getBytes(("UTF-8"));//$NON-NLS-1$
-			} catch (UnsupportedEncodingException uee) {
-				//cannot validate further
-				return value;
-			}
+			byte[] bytes = valueString.getBytes(StandardCharsets.UTF_8);
 			if (bytes.length > 65535) {
 				String msg = "Marker property value is too long: " + valueString.substring(0, 10000); //$NON-NLS-1$
 				Assert.isTrue(false, msg);
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/XMLWriter.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/XMLWriter.java
index 383f305..0c7d73d 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/XMLWriter.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/XMLWriter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@
 package org.eclipse.core.internal.resources;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -25,8 +26,8 @@
 	/* constants */
 	protected static final String XML_VERSION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
 
-	public XMLWriter(OutputStream output, String separator) throws UnsupportedEncodingException {
-		super(new OutputStreamWriter(output, "UTF8")); //$NON-NLS-1$
+	public XMLWriter(OutputStream output, String separator) {
+		super(new OutputStreamWriter(output, StandardCharsets.UTF_8));
 		tab = 0;
 		lineSeparator = separator;
 		println(XML_VERSION);
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Convert.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Convert.java
index 231b5b3..930b016 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Convert.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Convert.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,7 +10,7 @@
  *******************************************************************************/
 package org.eclipse.core.internal.utils;
 
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 
 public class Convert {
 
@@ -18,26 +18,14 @@
 	 * Converts the string argument to a byte array.
 	 */
 	public static String fromUTF8(byte[] b) {
-		String result;
-		try {
-			result = new String(b, "UTF8"); //$NON-NLS-1$
-		} catch (UnsupportedEncodingException e) {
-			result = new String(b);
-		}
-		return result;
+		return new String(b, StandardCharsets.UTF_8);
 	}
 
 	/**
 	 * Converts the string argument to a byte array.
 	 */
 	public static byte[] toUTF8(String s) {
-		byte[] result;
-		try {
-			result = s.getBytes("UTF8"); //$NON-NLS-1$
-		} catch (UnsupportedEncodingException e) {
-			result = s.getBytes();
-		}
-		return result;
+		return s.getBytes(StandardCharsets.UTF_8);
 	}
 
 	/**
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java
index 214f170..98b7a64 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java
@@ -13,6 +13,7 @@
 package org.eclipse.core.tests.resources;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.eclipse.core.internal.preferences.EclipsePreferences;
@@ -29,8 +30,8 @@
 	public class CharsetVerifier extends ResourceDeltaVerifier {
 		final static int IGNORE_BACKGROUND_THREAD = 0x02;
 		final static int IGNORE_CREATION_THREAD = 0x01;
-		private Thread creationThread = Thread.currentThread();
-		private int flags;
+		private final Thread creationThread = Thread.currentThread();
+		private final int flags;
 
 		CharsetVerifier(int flags) {
 			this.flags = flags;
@@ -303,7 +304,7 @@
 		}
 	}
 
-	public void testBug62732() throws UnsupportedEncodingException, CoreException {
+	public void testBug62732() throws CoreException {
 		IWorkspace workspace = getWorkspace();
 		IProject project = workspace.getRoot().getProject("MyProject");
 		IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
@@ -311,7 +312,7 @@
 		assertNotNull("0.5", anotherXML);
 		ensureExistsInWorkspace(project, true);
 		IFile file = project.getFile("file.xml");
-		ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_SPECIFIC_XML.getBytes("UTF-8")));
+		ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_SPECIFIC_XML.getBytes(StandardCharsets.UTF_8)));
 		IContentDescription description = file.getContentDescription();
 		assertNotNull("1.0", description);
 		assertEquals("1.1", anotherXML, description.getContentType());
@@ -762,18 +763,18 @@
 	 * deleted and recreated, with the same content id but a different content type.
 	 * This tricks the content type cache into returning an invalid result.
 	 */
-	public void testBug261994() throws UnsupportedEncodingException, CoreException {
+	public void testBug261994() throws CoreException {
 		//recreate a file with different contents but the same content id
 		IWorkspace workspace = getWorkspace();
 		IProject project1 = workspace.getRoot().getProject("Project1");
 		IFile file = project1.getFile("file1.xml");
-		ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_XML_ISO_8859_1_ENCODING.getBytes("ISO-8859-1")));
+		ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_XML_ISO_8859_1_ENCODING.getBytes(StandardCharsets.ISO_8859_1)));
 		ContentDescriptionManagerTest.waitForCacheFlush();
 		assertEquals("1.0", "ISO-8859-1", file.getCharset());
 
 		//delete and recreate the file with different contents
 		ensureDoesNotExistInWorkspace(file);
-		ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_XML_DEFAULT_ENCODING.getBytes("UTF-8")));
+		ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_XML_DEFAULT_ENCODING.getBytes(StandardCharsets.UTF_8)));
 		assertEquals("2.0", "UTF-8", file.getCharset());
 	}
 
@@ -881,7 +882,7 @@
 	/**
 	 * Tests Content Manager-based charset setting.
 	 */
-	public void testContentBasedCharset() throws CoreException, UnsupportedEncodingException {
+	public void testContentBasedCharset() throws CoreException {
 		IWorkspace workspace = getWorkspace();
 		IProject project = workspace.getRoot().getProject("MyProject");
 		try {
@@ -890,26 +891,26 @@
 			IFile file = project.getFile("file.xml");
 			assertEquals("0.9", "FOO", project.getDefaultCharset());
 			// content-based encoding is BAR
-			ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_XML_US_ASCII_ENCODING.getBytes("UTF-8")));
+			ensureExistsInWorkspace(file, new ByteArrayInputStream(SAMPLE_XML_US_ASCII_ENCODING.getBytes(StandardCharsets.UTF_8)));
 			assertEquals("1.0", "US-ASCII", file.getCharset());
 			// content-based encoding is FRED
-			file.setContents(new ByteArrayInputStream(SAMPLE_XML_ISO_8859_1_ENCODING.getBytes("ISO-8859-1")), false, false, null);
+			file.setContents(new ByteArrayInputStream(SAMPLE_XML_ISO_8859_1_ENCODING.getBytes(StandardCharsets.ISO_8859_1)), false, false, null);
 			assertEquals("2.0", "ISO-8859-1", file.getCharset());
 			// content-based encoding is UTF-8 (default for XML)
-			file.setContents(new ByteArrayInputStream(SAMPLE_XML_DEFAULT_ENCODING.getBytes("UTF-8")), false, false, null);
+			file.setContents(new ByteArrayInputStream(SAMPLE_XML_DEFAULT_ENCODING.getBytes(StandardCharsets.UTF_8)), false, false, null);
 			assertEquals("3.0", "UTF-8", file.getCharset());
 			// tests with BOM -BOMs are strings for convenience, encoded itno bytes using ISO-8859-1 (which handles 128-255 bytes better)
 			// tests with UTF-8 BOM
-			String UTF8_BOM = new String(IContentDescription.BOM_UTF_8, "ISO-8859-1");
-			file.setContents(new ByteArrayInputStream((UTF8_BOM + SAMPLE_XML_DEFAULT_ENCODING).getBytes("ISO-8859-1")), false, false, null);
+			String UTF8_BOM = new String(IContentDescription.BOM_UTF_8, StandardCharsets.ISO_8859_1);
+			file.setContents(new ByteArrayInputStream((UTF8_BOM + SAMPLE_XML_DEFAULT_ENCODING).getBytes(StandardCharsets.ISO_8859_1)), false, false, null);
 			assertEquals("4.0", "UTF-8", file.getCharset());
 			// tests with UTF-16 Little Endian BOM
-			String UTF16_LE_BOM = new String(IContentDescription.BOM_UTF_16LE, "ISO-8859-1");
-			file.setContents(new ByteArrayInputStream((UTF16_LE_BOM + SAMPLE_XML_DEFAULT_ENCODING).getBytes("ISO-8859-1")), false, false, null);
+			String UTF16_LE_BOM = new String(IContentDescription.BOM_UTF_16LE, StandardCharsets.ISO_8859_1);
+			file.setContents(new ByteArrayInputStream((UTF16_LE_BOM + SAMPLE_XML_DEFAULT_ENCODING).getBytes(StandardCharsets.ISO_8859_1)), false, false, null);
 			assertEquals("5.0", "UTF-16", file.getCharset());
 			// tests with UTF-16 Big Endian BOM
-			String UTF16_BE_BOM = new String(IContentDescription.BOM_UTF_16BE, "ISO-8859-1");
-			file.setContents(new ByteArrayInputStream((UTF16_BE_BOM + SAMPLE_XML_DEFAULT_ENCODING).getBytes("ISO-8859-1")), false, false, null);
+			String UTF16_BE_BOM = new String(IContentDescription.BOM_UTF_16BE, StandardCharsets.ISO_8859_1);
+			file.setContents(new ByteArrayInputStream((UTF16_BE_BOM + SAMPLE_XML_DEFAULT_ENCODING).getBytes(StandardCharsets.ISO_8859_1)), false, false, null);
 			assertEquals("6.0", "UTF-16", file.getCharset());
 		} finally {
 			try {
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java
index e8ce183..3a10089 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java
@@ -12,6 +12,7 @@
 package org.eclipse.core.tests.resources;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.attribute.FileTime;
 import java.util.HashSet;
@@ -863,14 +864,9 @@
 	 * @param file
 	 */
 	protected void modifyInWorkspace(IFile file) throws CoreException {
-		String m = getClassName() + ".modifyInWorkspace(IFile): ";
-		try {
-			String newContent = readStringInWorkspace(file) + "w";
-			ByteArrayInputStream is = new ByteArrayInputStream(newContent.getBytes("UTF8"));
-			file.setContents(is, false, false, null);
-		} catch (UnsupportedEncodingException e) {
-			fail(m + "0.0");
-		}
+		String newContent = readStringInWorkspace(file) + "w";
+		ByteArrayInputStream is = new ByteArrayInputStream(newContent.getBytes(StandardCharsets.UTF_8));
+		file.setContents(is, false, false, null);
 	}
 
 	/**
@@ -920,13 +916,7 @@
 	 * @param file
 	 */
 	protected String readStringInFileSystem(IFile file) {
-		String m = getClassName() + ".readStringInFileSystem(IFile): ";
-		try {
-			return new String(readBytesInFileSystem(file), "UTF8");
-		} catch (UnsupportedEncodingException e) {
-			fail(m + "0.0", e);
-		}
-		return null;
+		return new String(readBytesInFileSystem(file), StandardCharsets.UTF_8);
 	}
 
 	/**
@@ -935,13 +925,7 @@
 	 * @param file
 	 */
 	protected String readStringInWorkspace(IFile file) {
-		String m = getClassName() + ".readStringInWorkspace(IFile): ";
-		try {
-			return new String(readBytesInWorkspace(file), "UTF8");
-		} catch (UnsupportedEncodingException e) {
-			fail(m + "0.0", e);
-		}
-		return null;
+		return new String(readBytesInWorkspace(file), StandardCharsets.UTF_8);
 	}
 
 	protected void setAttribute(IFileStore target, int attribute, boolean value) {
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java
index 1467d3f..9ce7314 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java
@@ -11,6 +11,7 @@
 package org.eclipse.core.tests.resources.content;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.util.HashSet;
 import java.util.Set;
 import junit.framework.AssertionFailedError;
@@ -126,8 +127,8 @@
 		int fullIndex = 0;
 		// concatenates all byte arrays
 		for (byte[] content : contents) {
-			for (int j = 0; j < content.length; j++) {
-				full[fullIndex++] = content[j];
+			for (byte element : content) {
+				full[fullIndex++] = element;
 			}
 		}
 		return new ByteArrayInputStream(full);
@@ -335,60 +336,60 @@
 		assertNull("8.3", description);
 	}
 
-	public void testByteOrderMark() throws UnsupportedEncodingException, IOException {
+	public void testByteOrderMark() throws IOException {
 		IContentType text = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);
 		QualifiedName[] options = new QualifiedName[] {IContentDescription.BYTE_ORDER_MARK};
 		IContentDescription description;
 		// tests with UTF-8 BOM
-		String UTF8_BOM = new String(IContentDescription.BOM_UTF_8, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		String UTF8_BOM = new String(IContentDescription.BOM_UTF_8, StandardCharsets.ISO_8859_1);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNotNull("1.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		assertEquals("1.1", IContentDescription.BOM_UTF_8, description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// tests with UTF-16 Little Endian BOM
-		String UTF16_LE_BOM = new String(IContentDescription.BOM_UTF_16LE, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_LE_BOM + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		String UTF16_LE_BOM = new String(IContentDescription.BOM_UTF_16LE, StandardCharsets.ISO_8859_1);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_LE_BOM + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNotNull("2.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		assertEquals("2.1", IContentDescription.BOM_UTF_16LE, description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// tests with UTF-16 Big Endian BOM
-		String UTF16_BE_BOM = new String(IContentDescription.BOM_UTF_16BE, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_BE_BOM + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		String UTF16_BE_BOM = new String(IContentDescription.BOM_UTF_16BE, StandardCharsets.ISO_8859_1);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_BE_BOM + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNotNull("3.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		assertEquals("3.1", IContentDescription.BOM_UTF_16BE, description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// test with no BOM
-		description = text.getDescriptionFor(new ByteArrayInputStream(MINIMAL_XML.getBytes("ISO-8859-1")), options);
+		description = text.getDescriptionFor(new ByteArrayInputStream(MINIMAL_XML.getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("4.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 
 		// tests for partial BOM
 		// first byte of UTF-16 Big Endian + minimal xml
 		String UTF16_BE_BOM_1byte = new String(new byte[] {(byte) 0xFE}, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_BE_BOM_1byte + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_BE_BOM_1byte + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("5.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// first byte of UTF-16 Big Endian only (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=199252)
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_BE_BOM_1byte).getBytes("ISO-8859-1")), options);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_BE_BOM_1byte).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("5.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 
 		// first byte of UTF-16 Little Endian + minimal xml
-		String UTF16_LE_BOM_1byte = new String(new byte[] {(byte) 0xFF}, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_LE_BOM_1byte + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		String UTF16_LE_BOM_1byte = new String(new byte[] {(byte) 0xFF}, StandardCharsets.ISO_8859_1);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_LE_BOM_1byte + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("6.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// first byte of UTF-16 Little Endian only
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_LE_BOM_1byte).getBytes("ISO-8859-1")), options);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF16_LE_BOM_1byte).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("6.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 
 		// first byte of UTF-8 + minimal xml
-		String UTF8_BOM_1byte = new String(new byte[] {(byte) 0xEF}, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_1byte + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		String UTF8_BOM_1byte = new String(new byte[] {(byte) 0xEF}, StandardCharsets.ISO_8859_1);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_1byte + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("7.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// first byte of UTF-8 only
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_1byte).getBytes("ISO-8859-1")), options);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_1byte).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("7.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 
 		// two first bytes of UTF-8 + minimal xml
-		String UTF8_BOM_2bytes = new String(new byte[] {(byte) 0xEF, (byte) 0xBB}, "ISO-8859-1");
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_2bytes + MINIMAL_XML).getBytes("ISO-8859-1")), options);
+		String UTF8_BOM_2bytes = new String(new byte[] {(byte) 0xEF, (byte) 0xBB}, StandardCharsets.ISO_8859_1);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_2bytes + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("8.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 		// two first bytes of UTF-8 only
-		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_2bytes).getBytes("ISO-8859-1")), options);
+		description = text.getDescriptionFor(new ByteArrayInputStream((UTF8_BOM_2bytes).getBytes(StandardCharsets.ISO_8859_1)), options);
 		assertNull("8.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK));
 	}
 
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java
index 83a4e74..edfe889 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2015 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -57,7 +57,7 @@
 		super(name);
 	}
 
-	public void testReadSingleByte() throws UnsupportedEncodingException, IOException {
+	public void testReadSingleByte() throws IOException {
 		ByteArrayInputStream underlying = new ByteArrayInputStream(DATA.getBytes());
 		OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7);
 		assertEquals("1.0", '0', stream.read());
@@ -68,7 +68,7 @@
 		stream.close();
 	}
 
-	public void testReadBlock() throws UnsupportedEncodingException, IOException {
+	public void testReadBlock() throws IOException {
 		ByteArrayInputStream underlying = new ByteArrayInputStream(DATA.getBytes());
 		OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7);
 		stream.skip(4);
@@ -106,7 +106,7 @@
 		stream.close();
 	}
 
-	public void testMarkAndReset() throws UnsupportedEncodingException, IOException {
+	public void testMarkAndReset() throws IOException {
 		ByteArrayInputStream underlying = new ByteArrayInputStream(DATA.getBytes());
 		OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7);
 		assertEquals("0.1", 30, stream.available());
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java
index ccbcf09..71b5e9b 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2015 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -55,7 +55,7 @@
 		super(name);
 	}
 
-	public void testReadSingleChar() throws UnsupportedEncodingException, IOException {
+	public void testReadSingleChar() throws IOException {
 		CharArrayReader underlying = new CharArrayReader(DATA.toCharArray());
 		OpenLazyReader stream = new OpenLazyReader(underlying, 7);
 		assertEquals("1.0", '0', stream.read());
@@ -66,7 +66,7 @@
 		stream.close();
 	}
 
-	public void testReadBlock() throws UnsupportedEncodingException, IOException {
+	public void testReadBlock() throws IOException {
 		CharArrayReader underlying = new CharArrayReader(DATA.toCharArray());
 		OpenLazyReader stream = new OpenLazyReader(underlying, 7);
 		stream.skip(4);
@@ -104,7 +104,7 @@
 		stream.close();
 	}
 
-	public void testMarkAndReset() throws UnsupportedEncodingException, IOException {
+	public void testMarkAndReset() throws IOException {
 		CharArrayReader underlying = new CharArrayReader(DATA.toCharArray());
 		OpenLazyReader stream = new OpenLazyReader(underlying, 7);
 		assertTrue("0.1", stream.ready());