Skip to content

Commit

Permalink
Replace "UTF8" with StandardCharsets.UTF_8
Browse files Browse the repository at this point in the history
  • Loading branch information
merks committed Jul 21, 2024
1 parent 2a11005 commit 182230a
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -575,7 +576,7 @@ public List<EStructuralFeature> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -784,7 +785,7 @@ protected void createDefaultJETSettingsFile(List<Object> 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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> attributes) throws JETException
Expand Down Expand Up @@ -759,7 +760,7 @@ public static List<JETRootItem> 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<JETRootItem> result = new ArrayList<JETRootItem>();

class Listener implements JETParseEventListener, JETParseEventListener.CommentListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +26,7 @@

import org.eclipse.emf.ecore.resource.URIConverter;


/**
* <p>EMF implementation for the {@link org.eclipse.emf.ecore.resource.URIConverter.Cipher} interface using
* the DES encryption algorithm.</p>
Expand All @@ -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();
Expand All @@ -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.
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions tests/org.eclipse.emf.test.ecore.xcore/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 182230a

Please sign in to comment.