diff --git a/examples/org.eclipse.emf.exporter.html/src/org/eclipse/emf/exporter/html/HTMLExporter.java b/examples/org.eclipse.emf.exporter.html/src/org/eclipse/emf/exporter/html/HTMLExporter.java index 9e71a49e24..1654af6c65 100644 --- a/examples/org.eclipse.emf.exporter.html/src/org/eclipse/emf/exporter/html/HTMLExporter.java +++ b/examples/org.eclipse.emf.exporter.html/src/org/eclipse/emf/exporter/html/HTMLExporter.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -575,7 +576,7 @@ public List getDetails(EEnumLiteral enumLiteral) protected void save(String content) throws IOException { OutputStream outputStream = URIConverter.INSTANCE.createOutputStream(currentArtifactURI, null); - outputStream.write(content.getBytes("UTF-8")); + outputStream.write(content.getBytes(StandardCharsets.UTF_8)); outputStream.close(); } diff --git a/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java b/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java index 58a083d91e..5c3e6dae7c 100644 --- a/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java +++ b/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -433,7 +434,7 @@ protected void generate(Monitor progressMonitor, int style, List pluginVariables } progressMonitor.worked(1); - byte [] bytes = emitterResult.toString().getBytes(isUnicodeEscapeEncoded ? "ISO-8859-1" : "UTF-8"); + byte [] bytes = emitterResult.toString().getBytes(isUnicodeEscapeEncoded ? StandardCharsets.ISO_8859_1 : StandardCharsets.UTF_8); if (exists(targetFile)) { // Don't overwrite exising file @@ -459,7 +460,7 @@ protected void generate(Monitor progressMonitor, int style, List pluginVariables mergedResult = propertyMerger.getTargetProperties(); } - bytes = mergedResult.getBytes(isUnicodeEscapeEncoded ? "ISO-8859-1" : "UTF-8"); + bytes = mergedResult.getBytes(isUnicodeEscapeEncoded ? StandardCharsets.ISO_8859_1 : StandardCharsets.UTF_8); } } else diff --git a/plugins/org.eclipse.emf.codegen.ui/src/org/eclipse/emf/codegen/presentation/JETEditor.java b/plugins/org.eclipse.emf.codegen.ui/src/org/eclipse/emf/codegen/presentation/JETEditor.java index d445c20e31..e5018a6f03 100644 --- a/plugins/org.eclipse.emf.codegen.ui/src/org/eclipse/emf/codegen/presentation/JETEditor.java +++ b/plugins/org.eclipse.emf.codegen.ui/src/org/eclipse/emf/codegen/presentation/JETEditor.java @@ -10,11 +10,11 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -9040,14 +9040,7 @@ public InputStream openInputStream(String locationURI) throws JETException { IDocument document = buffer.getDocument(); String contents = document.get(); - try - { - return new ByteArrayInputStream(contents.getBytes("UTF-8")); - } - catch (UnsupportedEncodingException exception) - { - // UTF-8 is always supported. - } + return new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)); } } diff --git a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETCompileTemplateOperation.java b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETCompileTemplateOperation.java index b25ffa0bbe..4ac0d3e474 100644 --- a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETCompileTemplateOperation.java +++ b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETCompileTemplateOperation.java @@ -19,6 +19,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -679,9 +680,9 @@ void saveState(File stateFile) } String string = JETNature.toString(document); - string.getBytes("UTF-8"); + string.getBytes(StandardCharsets.UTF_8); out = new FileOutputStream(stateFile); - out.write(string.getBytes("UTF-8")); + out.write(string.getBytes(StandardCharsets.UTF_8)); out.close(); } catch (IOException exception) diff --git a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETNature.java b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETNature.java index 3e1235641a..d1eed6a208 100644 --- a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETNature.java +++ b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETNature.java @@ -18,6 +18,7 @@ import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -784,7 +785,7 @@ protected void createDefaultJETSettingsFile(List templateContainers, Lis writer.write("\n"); IFile jetSettingsFile = getProject().getFile(JET_NATURE_PROPERTIES_FILE); - InputStream sourceStream = new ByteArrayInputStream(writer.toString().getBytes("UTF-8")); + InputStream sourceStream = new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)); if (jetSettingsFile.exists()) { jetSettingsFile.setContents(sourceStream, true, true, null); @@ -801,7 +802,7 @@ protected void commitXML(Document document) throws CoreException, ClassNotFoundE { String documentXML = toString(document); IFile jetSettingsFile = getProject().getFile(JET_NATURE_PROPERTIES_FILE); - InputStream sourceStream = new ByteArrayInputStream(documentXML.getBytes("UTF-8")); + InputStream sourceStream = new ByteArrayInputStream(documentXML.getBytes(StandardCharsets.UTF_8)); if (jetSettingsFile.exists()) { jetSettingsFile.setContents(sourceStream, true, true, null); diff --git a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETParser.java b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETParser.java index c6427e33f9..d6ba880861 100644 --- a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETParser.java +++ b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/jet/JETParser.java @@ -66,6 +66,7 @@ import java.io.ByteArrayInputStream; import java.io.CharArrayWriter; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -712,7 +713,7 @@ public static JETDirectiveItem parseDirective(String directive) { try { - JETReader reader = new JETReader("", new ByteArrayInputStream(directive.getBytes("UTF-8")), "UTF-8"); + JETReader reader = new JETReader("", new ByteArrayInputStream(directive.getBytes(StandardCharsets.UTF_8)), "UTF-8"); JETParseEventListener parseEventListener = new JETParseEventListener() { public void handleScriptlet(JETMark start, JETMark stop, Map attributes) throws JETException @@ -759,7 +760,7 @@ public static List parseRootItems(String content) { try { - final JETReader reader = new JETReader("", new ByteArrayInputStream(content.getBytes("UTF-8")), "UTF-8"); + final JETReader reader = new JETReader("", new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), "UTF-8"); final List result = new ArrayList(); class Listener implements JETParseEventListener, JETParseEventListener.CommentListener diff --git a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/impl/DESCipherImpl.java b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/impl/DESCipherImpl.java index e7f79a6f67..91b78c080f 100644 --- a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/impl/DESCipherImpl.java +++ b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/impl/DESCipherImpl.java @@ -10,10 +10,12 @@ */ package org.eclipse.emf.ecore.resource.impl; + import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; @@ -24,6 +26,7 @@ import org.eclipse.emf.ecore.resource.URIConverter; + /** *

EMF implementation for the {@link org.eclipse.emf.ecore.resource.URIConverter.Cipher} interface using * the DES encryption algorithm.

@@ -40,46 +43,47 @@ public class DESCipherImpl implements URIConverter.Cipher { protected static final String ENCRYPTION_SCHEME = "DES"; + protected static final String UNICODE_FORMAT = "UTF-8"; protected String stringKey; + protected SecretKey key; - - + public DESCipherImpl() { this(null); } - + public DESCipherImpl(String key) { this.stringKey = key; } - + public OutputStream encrypt(OutputStream outputStream) throws Exception { Cipher cipher = Cipher.getInstance(ENCRYPTION_SCHEME); cipher.init(Cipher.ENCRYPT_MODE, getKey()); - + // The CipherOutputStream shoudln't close the underlying stream // outputStream = new FilterOutputStream(outputStream) - { - @Override - public void close() throws IOException { - // Do nothing - } + @Override + public void close() throws IOException + { + // Do nothing + } - @Override - public void write(byte[] b, int off, int len) throws IOException - { - out.write(b, off, len); - } - }; + @Override + public void write(byte[] b, int off, int len) throws IOException + { + out.write(b, off, len); + } + }; return new CipherOutputStream(outputStream, cipher); } - + public void finish(OutputStream outputStream) throws Exception { outputStream.close(); @@ -91,7 +95,7 @@ public InputStream decrypt(InputStream inputStream) throws Exception cipher.init(Cipher.DECRYPT_MODE, getKey()); return new CipherInputStream(inputStream, cipher); } - + public void finish(InputStream inputStream) throws Exception { // Do nothing. @@ -102,7 +106,7 @@ protected SecretKey getKey() throws Exception if (key == null) { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ENCRYPTION_SCHEME); - DESKeySpec keySpec = new DESKeySpec(stringKey.getBytes(UNICODE_FORMAT)); + DESKeySpec keySpec = new DESKeySpec(stringKey.getBytes(StandardCharsets.UTF_8)); key = keyFactory.generateSecret(keySpec); } return key; diff --git a/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/PersistenceTest.java b/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/PersistenceTest.java index 51b1bf7685..558ceb86ef 100644 --- a/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/PersistenceTest.java +++ b/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/PersistenceTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -922,7 +923,7 @@ protected void cipherTest(URIConverter.Cipher cipher) throws Exception ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream os = cipher.encrypt(baos); - os.write(originalMessage.toString().getBytes("UTF-8")); + os.write(originalMessage.toString().getBytes(StandardCharsets.UTF_8)); cipher.finish(os); os.close(); diff --git a/tests/org.eclipse.emf.test.ecore.xcore/META-INF/MANIFEST.MF b/tests/org.eclipse.emf.test.ecore.xcore/META-INF/MANIFEST.MF index 8c9a20f0db..9feb718d85 100644 --- a/tests/org.eclipse.emf.test.ecore.xcore/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.emf.test.ecore.xcore/META-INF/MANIFEST.MF @@ -19,8 +19,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.9.0,4.0.0)";resoluti org.junit;bundle-version="[4.12.0,5.0.0)", org.objectweb.asm;bundle-version="[5.0.0,11.0.0)";resolution:=optional, org.eclipse.xtext.ui.testing;bundle-version="[2.18.0,3.0.0)", - org.eclipse.ui.workbench;resolution:=optional;bundle-version="[3.6.0,4.0.0)", - org.eclipse.xtext.xbase.junit;bundle-version="[2.18.0,3.0.0)" + org.eclipse.ui.workbench;bundle-version="[3.6.0,4.0.0)";resolution:=optional Import-Package: org.hamcrest.core;version="[1.3.0,3.0.0)", org.junit.runner;version="[4.12.0,5.0.0)", org.junit.runner.manipulation;version="[4.12.0,5.0.0)", diff --git a/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/merger/JMergerTest.java b/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/merger/JMergerTest.java index 94fb4d1c57..acccd3ed96 100644 --- a/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/merger/JMergerTest.java +++ b/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/merger/JMergerTest.java @@ -21,6 +21,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -157,7 +158,7 @@ protected static void verifyMerge(File expectedOutput, String targetContents) try { out = new FileOutputStream(updateFile); - out.write(actualMerge.getBytes("UTF-8")); + out.write(actualMerge.getBytes(StandardCharsets.UTF_8)); } catch (Exception exception) {