Skip to content

Commit

Permalink
ST6RI-794: Specify StandardCharsets.UTF_8 to the byte-string
Browse files Browse the repository at this point in the history
  conversions.
* DynamicLibaryIndexProvider (getIndexFor):  Specify UTF_8 at
  InputStreamReader()
* PrecalculatedLibraryIndexProvider (getIndexFor): Ditto
* SysMLInteractiveLibraryIndexGenerator (main): Specify UTF_8 at
  getBytes()
* GenerateLibraryIndex (writeIndex): Ditto.
  • Loading branch information
himi committed Oct 2, 2024
1 parent 017e0ba commit 4c7fbe4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.WeakHashMap;

Expand Down Expand Up @@ -85,7 +86,7 @@ public LibraryIndex getIndexFor(Resource resource) {
LibraryIndex indexFromJson = LibraryIndex.EMPTY_INDEX;

if (indexFile.exists()) {
try (var reader = new InputStreamReader(indexFile.getContents())){
try (var reader = new InputStreamReader(indexFile.getContents(), StandardCharsets.UTF_8)) {
indexFromJson = LibraryIndex.fromJson(reader);
} catch (IOException e) {
//NOOP, return empty index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
package org.omg.kerml.xtext.library;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -78,13 +79,13 @@ public LibraryIndex getIndexFor(Resource resource) {

if (indexFile == null || !indexFile.exists()) return LibraryIndex.EMPTY_INDEX;

try (FileReader fileReader = new FileReader(indexFile)){

index = LibraryIndex.fromJson(fileReader);

try {
FileInputStream fis = new FileInputStream(indexFile);
InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
index = LibraryIndex.fromJson(isr);
} catch (FileNotFoundException e) {
//NOOP, return empty index
} catch (IOException e) {
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.EcoreUtil2;
Expand Down Expand Up @@ -74,7 +75,7 @@ public static void main(String[] args) throws IOException {

System.out.println("Writing index");
try (FileOutputStream fileStream = new FileOutputStream(indexFile, false)) {
fileStream.write(json.getBytes());
fileStream.write(json.getBytes(StandardCharsets.UTF_8));
}

System.out.println("Done.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -36,15 +37,13 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
Expand Down Expand Up @@ -152,7 +151,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
private void writeIndex(IProject project, String json, IProgressMonitor monitor) throws CoreException {
IFile file = project.getFile(LibraryIndex.FILE_NAME);

try (var inputStream = new ByteArrayInputStream(json.getBytes())){
try (var inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))){
if (file.exists()) {
file.setContents(inputStream, IFile.FORCE, monitor);
} else {
Expand Down

0 comments on commit 4c7fbe4

Please sign in to comment.