class DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator {

    static Map<String, Object> readDictionary(
            final InputStream is, final String id) throws IOException {
        final Map<String, Object> ht = new LinkedHashMap<>();
        if (id.endsWith(".cfg.json")) {
            final String name = "jcrinstall:".concat(id);
            String configId;
            int pos = id.lastIndexOf('/');
            if (pos == -1) {
                configId = id;
            } else {
                configId = id.substring(pos + 1);
            }
            pos = configId.indexOf('-');
            if (pos != -1) {
                configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos + 1));
            }
            configId = removeConfigExtension(configId);

            // read from input stream
            try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
                final Dictionary<String, Object> config = Configurations.buildReader()
                        .withIdentifier(configId).build(reader).readConfiguration();

                final Enumeration<String> i = config.keys();
                while (i.hasMoreElements()) {
                    final String key = i.nextElement();
                    ht.put(key, config.get(key));
                }
            }
        } else {
            try (final BufferedInputStream in = new BufferedInputStream(is)) {

                if (id.endsWith(".config")) {
                    // check for initial comment line
                    in.mark(256);
                    final int firstChar = in.read();
                    if (firstChar == '#') {
                        int b;
                        while ((b = in.read()) != '\n') {
                            if (b == -1) {
                                throw new IOException("Unable to read configuration.");
                            }
                        }
                    } else {
                        in.reset();
                    }
                    @SuppressWarnings("unchecked") final Dictionary<String, Object> config = ConfigurationHandler.read(in);
                    final Enumeration<String> i = config.keys();
                    while (i.hasMoreElements()) {
                        final String key = i.nextElement();
                        ht.put(key, config.get(key));
                    }
                } else {
                    final Properties p = new Properties();
                    in.mark(1);
                    boolean isXml = in.read() == '<';
                    in.reset();
                    if (isXml) {
                        p.loadFromXML(in);
                    } else {
                        p.load(in);
                    }
                    final Enumeration<Object> i = p.keys();
                    while (i.hasMoreElements()) {
                        final Object key = i.nextElement();
                        ht.put(key.toString(), p.get(key));
                    }
                }
            }
        }
        return ht;
    }

}