Source:
public boolean addOrRefreshModel(String name, final InputStream originalInputStream) { Resource resource = null; try { InputStream inputStream = null; if (originalInputStream != null) { byte[] bytes = IOUtils.toByteArray(originalInputStream); String validationResult = validateModel(name, new ByteArrayInputStream(bytes)); if (validationResult != null) { logger.warn("Configuration model '{}' has errors, therefore ignoring it: {}", name, validationResult); removeModel(name); return false; } inputStream = new ByteArrayInputStream(bytes); } resource = getResource(name); if (resource == null) { synchronized (resourceSet) { resource = getResource(name); if (resource == null) { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().remove("*"); resource = resourceSet.createResource(URI.createURI(name)); if (resource != null) { logger.info("Loading model '{}'", name); Map<String, String> options = new HashMap<String, String>(); options.put(XtextResource.OPTION_ENCODING, "UTF-8"); if (inputStream == null) { logger.warn( "Resource '{}' not found. You have to pass an inputStream to create the resource.", name); return false; } resource.load(inputStream, options); notifyListeners(name, EventType.ADDED); return true; } else { logger.warn("Ignoring file '{}' as we do not have a parser for it.", name); } } } } else { synchronized (resourceSet) { resource.unload(); logger.info("Refreshing model '{}'", name); if (inputStream != null) { resource.load(inputStream, Collections.EMPTY_MAP); } else { resource.load(Collections.EMPTY_MAP); } notifyListeners(name, EventType.MODIFIED); return true; } } } catch (IOException e) { logger.warn("Configuration model '" + name + "' cannot be parsed correctly!", e); if (resource != null) { resourceSet.getResources().remove(resource); } } return false; }

Target:
public boolean addOrRefreshModel(String name, final InputStream originalInputStream) { Resource resource = null; try { InputStream inputStream = null; if (originalInputStream != null) { byte[] bytes = IOUtils.toByteArray(originalInputStream); String validationResult = validateModel(name, new ByteArrayInputStream(bytes)); if (validationResult != null) { logger.warn("Configuration model '{}' has errors, therefore ignoring it: {}", name, validationResult); removeModel(name); return false; } inputStream = new ByteArrayInputStream(bytes); } resource = getResource(name); if (resource == null) { synchronized (resourceSet) { resource = getResource(name); if (resource == null) { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().remove("*"); resource = resourceSet.createResource(URI.createURI(name)); if (resource != null) { logger.info("Loading model '{}'", name); Map<String, String> options = new HashMap<String, String>(); options.put(XtextResource.OPTION_ENCODING, "UTF-8"); if (inputStream == null) { logger.warn( "Resource '{}' not found. You have to pass an inputStream to create the resource.", name); return false; } resource.load(inputStream, options); notifyListeners(name, EventType.ADDED); return true; } else { logger.warn("Ignoring file '{}' as we do not have a parser for it.", name); } } } } else { synchronized (resourceSet) { resource.unload(); logger.info("Refreshing model '{}'", name); if (inputStream != null) { resource.load(inputStream, Collections.EMPTY_MAP); } else { resource.load(Collections.EMPTY_MAP); } notifyListeners(name, EventType.MODIFIED); return true; } } } catch (IOException e) { logger.warn("Configuration model '{}' cannot be parsed correctly!", name, e); if (resource != null) { resourceSet.getResources().remove(resource); } } return false; }